2

I have one activity with many elements on it, when is first started it looks good and the images with gradients look prefect. for example this image

enter image description here

But after I touch the screen these images are changed badly, and they look ugly, I think this effect is called dithering

enter image description here

I not know if you will able to see the difference between this two images , but please zoom in and look carefully, and you will notice.

What is the problem ? what should I do ?

I tried with wrap_content I tried with fixed dimensions in px , in dip in everything it acts the same, at first it looks great and after any touch on the screen it change it self and it looks ugly, the image is the same but the rendering is very bad.

Please post answer if you really know how can I fix this(please do not guess answers, I guessed almost everything so far), Thanks

Lukap
  • 31,523
  • 64
  • 157
  • 244

1 Answers1

0

You can enable dithering by using code:

findViewById(R.id.ImageView01).getBackground().setDither(true);

Otherwise, you can apply dither from XML(define it inside the res/drawable folder) and set drawable as background

<?xml version="1.0" encoding="UTF-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/btn_background"
    android:dither="true" />
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • but I think this is available only on 2.3 and above, or I am wrong ? – Lukap Nov 11 '11 at 10:36
  • are you using 9-patch images for background? – Paresh Mayani Nov 11 '11 at 10:38
  • 1
    According to [the docs](http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setDither(boolean)), setDither() is available since API Level 1. – Felix Nov 11 '11 at 10:45
  • I do not have method ".setDither(true);" on my image view, I have "setDrawingCacheBackgroundColor" and 3 other methods but not setDither. – Lukap Nov 11 '11 at 10:49
  • @Lukap my dear just now i have already tested the same in SDK 2.2,its there. And how does it possible that it is not showing to you because as Felix has mentioned it already available from API level 1. – Paresh Mayani Nov 11 '11 at 10:57
  • just one more question, where should I define bitmap, and how set that xml file as background, if is not problem for you please edit your post, tnx – Lukap Nov 11 '11 at 11:13