Skip to content Skip to sidebar Skip to footer

Smooth Gradient On Different Devices

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 f

Solution 1:

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.

Solution 2:

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

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

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

Solution 3:

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.

Solution 4:

If the dither and RGBA_888 setting don't help on some phones, the solution can be to set the element layerType to software, to disable the hardware acceleration

android:layerType="software"

This fixed my problem on a Samsung S5 phone.

Post a Comment for "Smooth Gradient On Different Devices"