Android:ListView闪烁效果。关于如何摆脱这个的任何提示?

发布于 2024-08-07 12:27:47 字数 1053 浏览 4 评论 0原文

由于某种原因,每当我滚动项目列表时,列表视图内的背景就会消失并重新出现,从而产生我并不真正想要的“闪烁”效果。我已经尝试过以下建议:如何在 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

記柔刀 2024-08-14 12:27:47

您是否包含 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.

站稳脚跟 2024-08-14 12:27:47

这也可以从 Java(代码)端实现:listView.setCacheColorHint(Color.TRANSPARENT);

This can also be achieved from Java (code) side: listView.setCacheColorHint(Color.TRANSPARENT);

傲娇萝莉攻 2024-08-14 12:27:47

检查 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文