3

以下代码几乎与我想要实现的内容相同。Android。设置ListView的背景图像

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg"> 
    <ListView android:layout_height="wrap_content" android:id="@+id/levelList" android:layout_width="match_parent" android:layout_alignParentLeft="true"></ListView> 
</RelativeLayout> 

我想为整个ListView设置背景图像。此代码的问题是背景图像在滚动时闪烁或消失。

我使用sdk 2.2和一个模拟器来运行程序。

+0

您是否尝试将bg设置为listview? – Calvin 2012-03-22 16:08:20

+0

是的,并得到了相同的结果 – Gargo 2012-03-23 06:03:02

回答

5

你会想在你的ListView上设置android:cacheColorHint="#00000000"。这会将cacheColorHint设置为透明(注意#000000之后的额外2 0)并解决您的问题。或者,您可以将cacheColorHint设置为@android:color/transparent

您应该阅读this page on ListView backgrounds

+0

谢谢,它同样的事情我需要 – Gargo 2012-03-23 14:48:58