【问题标题】:Android: ListView Flicker effect. Any hints on how to get rid of this?Android:ListView 闪烁效果。关于如何摆脱这个的任何提示?
【发布时间】:2024-05-23 12:55:02
【问题描述】:

出于某种原因,每当我滚动浏览我的项目列表时,我的列表视图中的背景都会消失并重新出现,从而产生我并不真正想要的“闪烁”效果。我在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>

【问题讨论】:

    标签: android listview transparent flicker


    【解决方案1】:

    检查您的 theme.xml 中的 &lt;item name="android:windowBackground"&gt;@null&lt;/item&gt;。如果你有 - 删除它。我认为其中一个流行的资源以这条线为例(这就是我得到我的方式)。

    【讨论】:

    • 我其实没有自定义的theme.xml。你是在建议我创建一个吗?
    • 您可以尝试一下 - 我的首选项屏幕(即 ListView)也有类似的问题,但后来 - 我确实有自定义 theme.xml 和我在答案中的条目
    【解决方案2】:

    您是否添加了android:cacheColorHint="#00000000"?这是建议修复中最重要的部分。我刚刚尝试了您的代码(显然不是精确复制,因为您使用的是对项目特定资源的引用),它似乎可以工作。

    This post on the Android Developers blog 应该是你感兴趣的。

    【讨论】:

    • 太棒了...你不会相信我...我尝试附加 cacheColorHint 但我发现的每个资源都说 android:cacheColorHint="#000000" (注意零的数量显然没有说明 alpha )...现在它完全按照我的意愿工作了...非常感谢!
    【解决方案3】:

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

    【讨论】:

      最近更新 更多