开发者

My ListView backgrounds go black during scrolling - how to fix?

Ive specified white backgrounds for pretty much all widgets and it works, except when scrolling. The background c开发者_JAVA百科ontainer goes black during scrolling resulting in annoying flickering.


You will need to use the setCacheColorHint() method of ListView.

Example: list.setCacheColorHint(yourBackColor);

Explanation of the issue and solution here


ScrollingCache="false" in your activity's *.xml file for the list object should do the trick, too.


I fixed this problem by making the background color of the cells the same color as the ListView, so:

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

and then the row:

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

that completely got rid of the problem for me and seems like the best solution


Just put background on the top and no highlight or other bad effects simple and no need of hint or cache in listview layout android:background="#000000" for black background or android:background="#FFFFFF" for white

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜