Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Using linear gradient as background looks banded

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"?

like image 548
Francesco Laurita Avatar asked May 28 '10 10:05

Francesco Laurita


People also ask

What is angle in gradient Android?

attributes: android:angle Integer. The angle for the gradient, in degrees. 0 is left to right, 90 is bottom to top. It must be a multiple of 45.


1 Answers

As Romain Guy suggests:

listView.getBackground().setDither(true); 

solves my problem

If this is not enough especially for AMOLED and/or hdpi devices try this:

@Override public void onAttachedToWindow() {     super.onAttachedToWindow();     Window window = getWindow();     window.setFormat(PixelFormat.RGBA_8888); } 
like image 83
Francesco Laurita Avatar answered Oct 05 '22 23:10

Francesco Laurita