android - ListView 布局背景颜色在滚动时闪烁在图像加载时消失?

标签 android android-layout

我有一个带有布局的 ListView ,该布局具有与主布局不同的背景颜色的嵌套布局。

在这个嵌套布局中是一个 ImageView 。每当图像加载到 View 中时,此嵌套布局的背景颜色就会消失。在 ListView 滚动之前,背景不会返回。

此外,当滚动 ListView 时, ImageView 中的图像会再次绘制,此序列会再次发生,从而使列表具有闪烁效果。

我已经尝试在主布局和嵌套布局上设置 cacheColorHint 属性,但它似乎没有改变。

这是加载图像/滚动时发生的情况的示例图像。正如您所看到的,底部两个项目的背景颜色已经消失,其余的仍然有它们的背景颜色。

enter image description here

这是带有嵌套布局的 ListView 布局的一部分。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/race_entrant"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingRight="2dip"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
android:cacheColorHint="#E0EAF1">
<LinearLayout
    android:layout_height="fill_parent"
    android:layout_width="50dip"
    android:orientation="vertical"
    android:id="@+id/linearLeft"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    android:paddingTop="2dip"
    android:paddingBottom="2dip"
    android:background="#E0EAF1"
    android:cacheColorHint="#E0EAF1">
    <TextView
        android:id="@+id/txtEntrantNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/entrant_number"
        android:layout_gravity="center_horizontal"
        android:cacheColorHint="#E0EAF1" />
        <ImageView
            android:id="@+id/imgJockey"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="1dip"
            android:adjustViewBounds="true"
            android:cacheColorHint="#E0EAF1" />
</LinearLayout>

如何阻止嵌套布局的背景颜色像这样消失?

最佳答案

这为我解决了问题:listView.setCacheColorHint(Color.TRANSPARENT);

这可能只是帮助某人。

关于android - ListView 布局背景颜色在滚动时闪烁在图像加载时消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11007503/

相关文章:

Android EditText Multiline with SoftInputMode adjustPan

Android Studio,渲染问题

android - View 在 setText 上变为空

javascript - Phonegap android 4.1 致命信号 11 而在 2.2 中工作正常

android - 在我的真实手机上使用 android google map 只显示没有 map 的网格

android - Google 在 Android 应用内购买方面的收入份额是多少?

android - 如何在 ListView 中将 TextView 居中对齐到另一个 TextView 下方

android - 如何以编程方式使小按钮包裹小文本

android - 在不使用任何动画的情况下旋转相对布局

Android - ImageView - 多屏幕支持 - 将高度/宽度设置为 dp 或 match_parent/wrap_content?