16

Ive specified white backgrounds for pretty much all widgets and it works, except when scrolling. The background container goes black during scrolling resulting in annoying flickering.

Eno
  • 10,730
  • 18
  • 53
  • 86
  • possible duplicate: http://stackoverflow.com/questions/2803028/gets-flickering-layouts-background-while-scrolling-the-listview-in-android – Praveen Aug 25 '10 at 07:13

4 Answers4

54

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

Example: list.setCacheColorHint(yourBackColor);

Explanation of the issue and solution here

likeitlikeit
  • 5,563
  • 5
  • 42
  • 56
jqpubliq
  • 11,874
  • 2
  • 34
  • 26
  • 18
    Just wanted to add this in case someone else finds this thread. I used 'android:cacheColorHint="#00000000"' on the ListView layout to fix. – Eno Mar 30 '10 at 22:04
4

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

ubuntudroid
  • 3,680
  • 6
  • 36
  • 60
  • 9
    That's a terrible idea, it makes scrolling/flinging the list a lot slower. – Romain Guy Mar 30 '10 at 23:44
  • 1
    Oh, good to know! For me it always worked well. Nevertheless, I will avoid this in the future and use the setCacheColorHint() solution... Thanks! – ubuntudroid Mar 31 '10 at 09:32
0

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>
Piyush
  • 18,895
  • 5
  • 32
  • 63
John BG
  • 346
  • 3
  • 10
0

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

John
  • 3,769
  • 6
  • 30
  • 49