Android. Set background image of ListView

The following code is pretty much the same as what I want to achieve.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/bg">
    <ListView android:layout_height="wrap_content" android:id="@+id/levelList" android:layout_width="match_parent" android:layout_alignParentLeft="true"></ListView>
</RelativeLayout>

      

I want to set a background image for the whole ListView. The problem with this code is that the background image flickers or disappears when scrolling.

I am using sdk 2.2 and an emulator to run the program.

+3


source to share


1 answer


You want to set android:cacheColorHint="#00000000"

to your ListView. This will make the cacheColorHint transparent (note the extra 2 0

after #000000

) and fix the problem. Alternatively, you can set the cacheColorHint parameter to @android:color/transparent

.



You should read this page in a ListView background .

+5


source







All Articles