3

I have created a specific Listview which exists out of the following elements to create a scrollable list with every row containing a Image on the left side and some text on the right side.The xml i am using for the listview is like this :

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="#C8C8C8"
>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>
<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    android:divider="#C8C8C8"
    android:background="#C8C8C8"/>

and for the listview's row the xml code i am using given below:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/bg_row"
>
    <ImageView
        android:layout_width="wrap_content"
        android:paddingLeft="10px"
        android:paddingRight="15px"
        android:paddingTop="5px"
        android:paddingBottom="5px"
        android:layout_height="wrap_content"
        android:src="@drawable/bg_image"
    />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="5px"
        android:paddingBottom="5px"
        android:textSize="16sp"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:maxHeight="50px"/>
</LinearLayout>

As long as the screen is shown statically (as in no movement) it will be shown correctly, but when I start scrolling through the list the background of the row-item (an "icon" as can be shown in the code) will be shown corretcly but the background of the "root" layout will become completely black... when the scrolling stops the background will, most of the times, get back it's color... As I test I also added a TextView in that root-element with the same background, this one will detain it's color when the List is scrolled... Any idea why this is happening, and how to solve this ?

jpihl
  • 7,941
  • 3
  • 37
  • 50
sanya
  • 41
  • 5

2 Answers2

0

add a attribute on the ListView Tag

android:cacheColorHint="#00000000" // setting as a transparent color
0

You need to set your ListView's cache color to the same as your ListView's color:

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    android:divider="#C8C8C8"
    android:background="#C8C8C8"
    android:cacheColorHint="#C8C8C8"  />

Sidenote: If you want your divider to be invisible, you can also do this as followed:

android:divider="@null"
DroidBender
  • 7,762
  • 4
  • 28
  • 37