Android ListView滚动时背景颜色变化——colorCacheHint不能解决问题

5

我正在使用适配器来创建自定义的列表视图,但是在我的Nexus 7上一切看起来都很好,但是在我的HTC Incredible 2上遇到了一个背景颜色变化的问题。这是我的XML文件,并设置了cacheColorHint。我也尝试过使用#AA00000。有什么建议吗?我还尝试通过setCacheColorHint在活动中设置它,但是仍然没有效果。

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal"     
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:padding="10dp"
 android:background="#AA000000"
 android:cacheColorHint="#00000000">

 <ImageView android:id="@+id/ExhibitListIcon"
 android:contentDescription="Exhibit List Icon"
 android:layout_width="wrap_content"
 android:layout_height="fill_parent"
 android:gravity="center_vertical"
 android:layout_marginRight="15dp"
 android:layout_marginTop="5dp"
 android:layout_marginBottom="5dp" />

 <TextView android:id="@+id/ExhibitListTitle"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:gravity="center"
 android:textStyle="bold"
 android:textSize="22dp"
 android:textColor="#FFFFFF"
 android:layout_marginTop="5dp"
 android:layout_marginBottom="5dp" />

 </LinearLayout>
3个回答

21

你可以尝试在声明Listview的xml文件中设置cachecolorhint,而不是在LinearLayout中进行设置:

在布局文件中使用以下代码:

android:cacheColorHint="#0000"

或者在Java代码中使用

listView.setCacheColorHint(Color.TRANSPARENT);
希望这有所帮助!

哇,对我来说,在使用兼容性导航抽屉列表时出现了问题,但只有在旧设备上才会出现问题,我完全不知道发生了什么!谢谢 :-) - Daniel Wilson

6
在您的ListView中添加以下行:

android:cacheColorHint="@android:color/transparent"

2
listView.setCacheColorHint(Color.TRANSPARENT);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接