Http://stackoverflow.com/questions/8417608/awful-background-image-quality-in-android/8417703#8417703
First of all, make sure that your original image looks good so you're not just getting the problem from there.
Then, in your oncreate () method, do:
Code1:
Getwindow().Setformat(Pixelformat.Rgba_8888);Getwindow().Addflags(Windowmanager.Layoutparams.Flag_dither);
And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) Add the following where you load your views:
Code2:
Bitmapfactory . Options Options = New Bitmapfactory . Options (); Options . Inpreferredconfig = Bitmap . Config . Argb_8888 ; Bitmap Gradient = Bitmapfactory . Decoderesource ( Getresources (), R . Drawable . Gradient , Options ); Findviewbyid ( R . ID . Main ). Setbackgrounddrawable ( New Bitmapdrawable ( Gradient ));
Comparison between different approaches :( these are all screenshots from the resulting application)
my source images (64 colors to the left, 24 bit to the right):
image1 and image2:
1: raw 64-color image (image1) set as background from layout XML:
2: the same image (image1 ), using code1 :
3: The same image (image1) using both code1 and code2 :
4: image2, loaded with code1 and code2 (in this case the dithering is not really important as both the source and destination use 8 bits per color):