安卓:设置ListView的背景图片

3
以下代码几乎是我想实现的相同内容。
<?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和模拟器来运行程序。

你试过将背景设置为 ListView 吗? - Calvin
是的,我已经得到了相同的结果。 - Gargo
1个回答

5
你需要在ListView上设置android:cacheColorHint="#00000000"。这将把cacheColorHint设置为透明(注意在#000000后面有2个额外的0),并解决你的问题。或者,你可以将cacheColorHint设置为@android:color/transparent
你应该阅读此页面关于ListView背景的内容

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