代码之家  ›  专栏  ›  技术社区  ›  Eno

我的ListView背景在滚动时变黑-如何修复?

  •  16
  • Eno  · 技术社区  · 15 年前

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

    4 回复  |  直到 8 年前
        1
  •  54
  •   likeitlikeit Srivathsa Harish Venkataramana    12 年前

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

    例子: list.setCacheColorHint(yourBackColor);

    问题说明及解决办法 here

        2
  •  4
  •   ubuntudroid    15 年前

    在活动的*.xml文件中,对于列表对象,scrollingcache=“false”也应该做到这一点。

        3
  •  0
  •   John    11 年前

    我通过使单元格的背景色与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>
    

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

        4
  •  0
  •   Piyush    8 年前

    只需将背景放在顶部,不需要突出显示或其他不良效果简单,不需要提示或缓存 在ListView布局中 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>