Android:ListView闪烁效果。关于如何摆脱这个的任何提示?
由于某种原因,每当我滚动项目列表时,列表视图内的背景就会消失并重新出现,从而产生我并不真正想要的“闪烁”效果。我已经尝试过以下建议:如何在 Android 中使 ListView 透明? 但它没有由于某种原因不起作用。有什么建议吗?
<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>
For some reason, whenever I scroll through my list of items, the background inside my listview disappears and reappears giving rise to a "flicker" effect which I don't really want. I've tried the suggestion at: How to make a ListView transparent in Android? but it doesn't work for some reason. Any suggestions?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否包含
android:cacheColorHint="#00000000"
?这是拟议修复中最重要的部分。我刚刚尝试了您的代码(显然不是精确的复制,因为您正在使用对特定于项目的资源的引用),并且它似乎有效。Android 开发者博客上的这篇文章 应该是您感兴趣的。
Did you include
android:cacheColorHint="#00000000"
? It's the most important part of the proposed fix. I've just tried your code (obviously not an exact reproduction, as you're using references to project-specific resources) with it, and it seems to work.This post on the Android Developers blog should be of your interest.
这也可以从 Java(代码)端实现:
listView.setCacheColorHint(Color.TRANSPARENT);
This can also be achieved from Java (code) side:
listView.setCacheColorHint(Color.TRANSPARENT);
检查 theme.xml 中的
- @null
。如果有 - 将其删除。我认为流行的资源之一以这一行为例(这就是我得到我的)。Check your theme.xml for
<item name="android:windowBackground">@null</item>
. If you have it - remove it. I think one of the popular resources gives this line as example (that's how I got mine).