出于某种原因,每当我滚动浏览项目列表时,listview中的背景就会消失并再次出现,从而产生“闪烁”效果,我并不是真的想要这样做。我在How to make a ListView transparent in Android?尝试过这个建议,但由于某些原因它无效。有什么建议吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screenLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@color/title_background"
android:text="@string/whatsnew_title"
>
</TextView>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
答案 0 :(得分:21)
您是否包含android:cacheColorHint="#00000000"
?这是拟议修复中最重要的部分。我刚试过你的代码(显然不是一个精确的复制,因为你正在使用对项目特定资源的引用),它似乎有效。
答案 1 :(得分:2)
这也可以从Java(代码)方面实现:listView.setCacheColorHint(Color.TRANSPARENT);
答案 2 :(得分:1)
检查你的theme.xml <item name="android:windowBackground">@null</item>
。如果你有 - 删除它。我认为其中一个受欢迎的资源以这一行为例(这就是我的方式)。