Skip to content Skip to sidebar Skip to footer

Android: How To Draw An Imageview With The Same Size Regardless Of Device?

I want to put a toolbar in my application. The toolbar will use ImageViews as application buttons. I would like the ImageViews to be the exact same size regardless device; by 'sa

Solution 1:

Ok, I finally figured out what is going on:

The problem is that a image button who's width is specified as 10mm, shows as about 7mm on my Galaxy tab, and about 9mm on my Iconia Tab. There are 2 reasons for this rather significant difference:

  1. The Iconia Tab reports its xdpi as ~160, when its actual xdpi is ~150.
  2. Honeycomb uses a new drawable for its button background, with significantly smaller margin than the drawable in Froyo.

Issue 1 accounts for about .6mm of the difference, Issue 2 accounts for the remainder. Issue 2 can be solved by choosing one of the two backgrounds, packaging it with the application, and specifying it as the background for the ImageButton. Issue 1 cannot be resolved, but the difference it creates is relatively minor once issue 2 is dealt with.

Solution 2:

You have two basic approaches:

  1. Use supplied resource indentifiers - hdpi/ldpi/etc - and just rely on the OS.

  2. Use xdpi/ydpi in DisplayMetrics class. They are supposed to return the exact physical pixels per inch and scale the image manually with a corresponding scale factor. This, of course, will slow down performance. What is more - I am not sure whether these readings will be correct.

Solution 3:

Did you try stuff in the no-dpi resource identifier. Honestly I'm not sure what you would get out of this but it's worth a shot.

Post a Comment for "Android: How To Draw An Imageview With The Same Size Regardless Of Device?"