【问题标题】:Listview layout background color flickers on scroll disappears on image load?Listview 布局背景颜色在滚动时闪烁在图像加载时消失?
【发布时间】:2013-02-18 18:39:07
【问题描述】:

我有一个布局的列表视图,该布局具有与主布局不同的背景颜色的嵌套布局。

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

此外,当滚动列表视图时,图像视图中的图像再次被绘制,此序列再次发生,这使列表具有闪烁效果。

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

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

这是带有嵌套布局的列表视图布局部分。

<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>

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

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

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

    这可能只是帮助某人。

    【讨论】:

      【解决方案2】:

      我设法通过设置图像视图的背景颜色来实现这一点。

      执行此操作的 xml 是:

      android:background="#E0EAF1"
      

      现在加载图像时,背景颜色不会改变。

      【讨论】:

        猜你喜欢
        • 2011-02-17
        • 2018-10-25
        • 2017-05-22
        • 1970-01-01
        • 2020-08-04
        • 1970-01-01
        • 2017-08-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多