views:

1976

answers:

2

Hi All! I'm trying to apply a linear gradient to my ListView. This is the content of my drawable xml:

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <gradient 
        android:startColor="#3A3C39" 
        android:endColor="#181818"
        android:angle="270"
     />
    <corners android:radius="0dp" />
</shape>

So I apply it to my ListView with:

android:background="@drawable/shape_background_grey"

It works but it looks very "banded" on emulator and on a real device too.

Is there any way to reduce this "behaviour"?

+2  A: 

You can simply enable dithering on your Drawable object.

Romain Guy
Yes it works!Ty very much.BTW I tried to use this property into the drawable xml definition but as I read better into the documentation, this property is supported only for the selector element.
Francesco
Unfortunly this not works on Android version > 1.5. I tested on real device with Android 1.6 and Android 1.5. Adding dither to my drawable gradient not works. The devices are both 320 x 480 (180 ppi). Any suggestion? Tnx
Francesco
All credits go to Eric Burke for this - http://stuffthathappens.com/blog/2010/06/04/android-color-banding/
Alex Volovoy
+2  A: 

As Romain Guy suggests:

listView.getBackground().setDither(true);

solves my problem

Francesco
This not works on android 1.6 and above. See my other comment
Francesco
Can you do this in xml?
Thomas Ahle