滚动时背景ListView变为黑色

我创建了一个特定的列表,该列表存在于以下元素之外,以创建一个可滚动的列表,每行的左侧包含一个图像,右侧包含一些文本:


首先使用“根”布局:


<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent"

    android:background="#C8C8C8"

    >

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"/>

    <ListView

        android:id="@android:id/list"

        android:layout_width="fill_parent" 

        android:layout_height="fill_parent"

        android:drawSelectorOnTop="false"

        android:divider="#C8C8C8"

        android:background="#C8C8C8"/>

</LinearLayout>

然后在ListView中放置以下“行”项:


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:orientation="horizontal"

    android:background="@drawable/bg_row"

>

    <ImageView

        android:layout_width="wrap_content"

        android:paddingLeft="10px"

        android:paddingRight="15px"

        android:paddingTop="5px"

        android:paddingBottom="5px"

        android:layout_height="wrap_content"

        android:src="@drawable/bg_image"

    />

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:paddingTop="5px"

        android:paddingBottom="5px"

        android:textSize="16sp"

        android:textColor="#000000"

        android:layout_gravity="center"

        android:maxHeight="50px"/>

</LinearLayout>

只要屏幕是静态显示的(静止不动),它将正确显示,但是当我开始滚动列表时,将显示行项目的背景(代码中可以显示“图标”)可以正确显示,但“根”布局的背景将变为完全黑色...当滚动停止时,背景通常会恢复其颜色...当我测试时,我还在TextView该根元素中添加了一个在相同的背景下,滚动列表时,该颜色将保留其颜色...知道为什么会发生这种情况以及如何解决此问题吗?


芜湖不芜
浏览 467回答 4
4回答

慕后森

android:id="@android:id/list"android:layout_width="fill_parent"&nbsp;android:layout_height="fill_parent"android:drawSelectorOnTop="false"android:divider="#C8C8C8"android:background="#C8C8C8"android:cacheColorHint="#00000000"/>

一只斗牛犬

在ListView标签上添加属性android:cacheColorHint="#00000000" // setting transparent color

神不在的星期二

非常简单,只需在布局文件中使用以下行:android:scrollingCache="false"像这样:<ListView&nbsp;android:layout_width="fill_parent"android:layout_height="fill_parent"android:scrollingCache="false"/>

喵喔喔

您可以这样使用:list.setCacheColorHint(Color.TRANSPARENT);list.requestFocus(0);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android