smooth gradient on different devices

Viewed 5792

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

Is it possible to dither a gradient drawable?

4 Answers

You can use a custom shape (put it in /drawable/gradient.xml or something like that):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#000000"
    android:endColor="#ffffff"
    android:angle="90"/>
</shape>

This way it will be painted by the os and it should be perfectly smooth.

Related