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">
<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"?
The only thing that worked for me was to set a slightly-transparent alpha channel on both the startColor and endColor.
I got the idea to try this from this other SO question: android:dither=“true” does not dither, what's wrong?
You can simply enable dithering on your Drawable object.
For me on HTC Desire works like this
If the dither and RGBA_888 setting don't help on some phones, the solution can be to set the element
layerType
tosoftware
, to disable the hardware accelerationThis fixed my problem on a Samsung S5 phone.
For me the banding disappeared when I set the android:useLevel="true" on the gradient: gradient_dark.xml
But first I tried using a Layer-List with a "noise" drawable to remove the banding, it helps but there is still some banding.
The "noise_repeater" drawable i created and used
As Romain Guy suggests:
solves my problem
If this is not enough especially for AMOLED and/or hdpi devices try this: