In my app i have gradient as drawable which i am using as background and i wan't it to make it look as smooth as possible. After googling and trying by myself i came up with the following. On nexus one if you call only setDither(true) your gradient is still banding so you have to set PixelFormat like this Window.setFormat(PixelFormat.RGBA_8888). But on the other side G1 does not support RGBA_8888 so calling it make the gradient even uglier than before so Window.setFormat(PixelFormat.RGBA_8888) will not work well on devices that don't support it.
What is the correct way smooth my gradient on all devices on which my app will run.
PS: i found some related topics
How to draw a smooth/dithered gradient on a canvas in Android
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.
When loading your image, set the pixelFormat to RGB_565 and setDither to true, if you are drawing it straight to the screen with no other modification.
The displays typically aren't 24bit, that should typically do it good enough, at least pretty consistently all around.
You don't need to use 8888 if you don't need the alpha and won't be modifying the image data. It will displayed on 99% of mobile displays as 16bit color and not 24bit, since that is what the panels support.
N1 will always have issues close up because the matrix they use for the panel has double the green resolution.
Open your image in Photoshop (or Gimp or Paint.NET or whatever) and add a small quantity of noise. Then you don't have to do anything in code.
You can use a custom shape (put it in /drawable/gradient.xml or something like that):
This way it will be painted by the os and it should be perfectly smooth.