【问题标题】:My ListView backgrounds go black during scrolling - how to fix?我的 ListView 背景在滚动过程中变黑 - 如何修复?
【发布时间】:2011-02-02 15:14:06
【问题描述】:

我已经为几乎所有的小部件指定了白色背景,并且它可以工作,除了滚动时。背景容器在滚动过程中变黑,导致烦人的闪烁。

【问题讨论】:

标签: android listview scroll colors


【解决方案1】:

只需将背景放在顶部,没有高亮或其他不良效果简单,无需提示或缓存 在列表视图布局中 android:background="#000000" 用于黑色背景或android:background="#FFFFFF" 用于白色

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/testscheck"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="12dp"
        android:layout_weight="1"
        android:layout_gravity="left|center"
        android:gravity="left"
        android:textColor="@color/ics"
        android:textSize="14sp"
         />
</LinearLayout>

【讨论】:

    【解决方案2】:

    我通过使单元格的背景颜色与 ListView 相同的颜色解决了这个问题,所以:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="#FFFFFF">
    
        <ListView 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#FFFFFF"> <---- Background color of ListView
        </ListView>
    </LinearLayout>
    

    然后是行:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="8dip"
        android:background="#FFFFFF"> <--- Background color of the cell
    
        <LinearLayout 
            android:id="@+id/projects_cover_row_image_layout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:background="#444444"
            android:layout_centerInParent="true"
            android:layout_marginRight="8dip">
    
            <ImageView 
                android:id="@+id/projects_cover_row_image"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:contentDescription="@string/projects_image_content"/>
        </LinearLayout>
    
        ...
    
    </RelativeLayout>
    

    这完全解决了我的问题,似乎是最好的解决方案

    【讨论】:

      【解决方案3】:

      您需要使用 ListView 的setCacheColorHint() 方法。

      例如:list.setCacheColorHint(yourBackColor);

      问题说明及解决方案here

      【讨论】:

      • 只是想添加这个以防其他人发现这个线程。我在 ListView 布局上使用了 'android:cacheColorHint="#00000000"' 来修复。
      【解决方案4】:

      您的活动的 *.xml 文件中的列表对象的 ScrollingCache="false" 也应该可以解决问题。

      【讨论】:

      • 这是一个糟糕的主意,它会使滚动/翻动列表变慢很多。
      • 哦,很高兴知道!对我来说,它总是运作良好。不过,我以后会避免这种情况并使用 setCacheColorHint() 解决方案...谢谢!
      猜你喜欢
      • 2011-02-19
      • 2012-07-03
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      相关资源
      最近更新 更多