滚动时背景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 ,元素具有相同的背景,当滚动列表时,这个元素会留下它的颜色......任何想法为什么会发生这种情况,以及如何解决这个问题?


ListView标签上添加一个属性

android:cacheColorHint="#00000000" // setting transparent color

有关更多详情,请查看此博客


这非常简单,只需在布局文件中使用这一行即可:

android:scrollingCache="false"

喜欢这个:

<ListView 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollingCache="false"
/>

你可以这样使用:

list.setCacheColorHint(Color.TRANSPARENT);
list.requestFocus(0);
链接地址: http://www.djcxy.com/p/4133.html

上一篇: Background ListView becomes black when scrolling

下一篇: Is there any way to change android:windowSoftInputMode value from java class?