0

I have an listview and the individual items in the listview are inflated from custom layout. I do not have any problem with that. My problem is when I put a background to the item, it is rendered very strange, it is like re-sized and and it looks ugly:

enter image description here enter image description here

I put different values for the height of the item like wrap_content, like the exact height of the real image in px, I tried values in dip but nothing helps. The original image it is ok, it looks just like it should but when I put it as background for the item it looks ugly. This is not first time I experience something like this. Somethimes putting wrap_content helps but not always. I do not understand the background of the problem why is this happening?

Why sometimes when I put some image as background even have some gradients and so on, it works just perfectly and why sometimes it don't?

I had experience where I had linear layout with background and when the size of the layout was wrap_content of let say 77dip it looked very ugly (with scratches in the middle) and when I put 78 or 76dip height the background looked very nice, again on 73dip the scratches in the middle ware shown. I never understand this strange behavior, can someone please clarify this and what is the best practice for doing things like this.

I read multiple screen support but I never meet solution for this kind of problem I never even read that someone else have experienced something like this.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
Lukap
  • 31,523
  • 64
  • 157
  • 244

2 Answers2

0

Use 9-patch tool to create scalable 9-patch image. Once you create image using this, it will support all the screen resolutions and mostly looks same in every resolutions.

More information about stretchable patches inside the 9-patch image.

Nice tutorial with great examples: http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

I think you're getting into banding/dithering problems.

The origin of the problem is that the screen can't match the colour you exactly want and will "round" it to the nearest possible value. This might yield bad results in images with progressive colours like gradients.

See this link: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

Enabling dithering should help you.

Pedro Loureiro
  • 11,436
  • 2
  • 31
  • 37
  • this is nice tip but I need something more, cause I still makes problems with the gradients, I guess I need some guidelines about constructing gradients for android, my experience says that the gradients should me sooth, but still I want to find something more about this topic, if you know some good tutorial please send me some links – Lukap Nov 09 '11 at 15:41