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?
To create a smooth looking Gradient or Blend in Illustrator look to these steps. If you are using the Blend Tool and you are getting banding, double-click on the Blend Tool in the Tool Palette. This should bring up a dialog box, make sure the pull-down menu is set to Smooth Color.
To put it simply, they have to mix colors that are far away from each other on the color wheel. In this case, it is necessary to introduce an in-between element to create a good-looking gradient. It's a so-called 3-stop gradient that uses a new color as the connecting point between the two original colors.
To create smooth gradient transitions, we want to work in 16-bit mode (Image-Mode-16Bits/Channel) to eliminate most of the color banding. Create a new layer for the gradient by selecting Layer-New Fill Layer-Gradient. Accept the default setting and click OK. This will bring up the Gradient Fill dialogue box.
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):
<?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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With