Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView style issue with background while scroll

I need to style ListView and can't figure out why It turns to black background when scroll.. I have ListView inside LinearLayout and that layout has Background set to image.

This is what I have for ListView:

<style name="MyListView" parent="@android:style/Widget.ListView">
        <item name="android:listSelector">@drawable/selector_list_item</item>
    </style>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:state_focused="true"
          android:drawable="@drawable/shape_list_item_normal" />
    <item android:state_pressed="true"
          android:drawable="@drawable/shape_list_item_pressed" />
    <item android:state_focused="true"
          android:drawable="@drawable/shape_list_item_normal" />
</selector>

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:startColor="#80ffffff" android:endColor="#80eff3ef" android:angle="45" />
    <padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:startColor="#80808080" android:endColor="#80eff3ef" android:angle="45" />
    <padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>

When I apply MyListView style I don't see much happening. When I click on item - yes, I see gradient. When ListView stable - I see background as it should be from parent layout. When I scroll - I see black background, it's erasing parent's background. And I would be fine with that if I knew how to set it with something else..

like image 208
katit Avatar asked May 24 '11 18:05

katit


1 Answers

Use the following property in the xml of listView:

android:cacheColorHint="@android:color/transparent"
like image 65
Dinesh Sharma Avatar answered Nov 15 '22 21:11

Dinesh Sharma