Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. Set ListView's background Image

The following code is almost the same thing 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 setup a background image for the whole ListView. The problem of this code is that background image blinks or disappears on scrolling.

I use sdk 2.2 and an emulator to run the program.

like image 924
Gargo Avatar asked Dec 06 '25 08:12

Gargo


1 Answers

You'll want to set android:cacheColorHint="#00000000" on your ListView. This will set the cacheColorHint to transparent (notice the extra 2 0's after #000000) and fix your problem. Alternatively you can set the cacheColorHint to @android:color/transparent.

You should read this page on ListView backgrounds.

like image 55
Reinier Avatar answered Dec 07 '25 22:12

Reinier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!