Skip to content Skip to sidebar Skip to footer

Android : My Button Image Is Enlarged In The App?

I use a button with an image as its background, this image has a size of 30x29, but it's resized and enlarged x2 (I think). Here is the XML code of my button :

Where px is the final image size in pixels, dp is the desired size in density-independent units, and dpi is the target density.

Simplifying this formula, using the size in pixels of your mdpi images as the baseline:

ldpi = mdpi * 0.75hdpi = mdpi * 1.5xhdpi = mdpi * 2.0

Going back to your sample code, if you want a button that is 30dp by 30dp, you should be providing images for each density:

  • ldpi: 23px x 23px
  • mdpi: 30px x 30px
  • hdpi: 45px x 45px
  • xhdpi: 60px x 60px

Solution 2:

I think that may be folder issue. Where have you put the image file? (possibly there would not be a problem if You have it in drawable-hdpi)

EDIT

ps - there is also a dp unit thing, which is pixel-independent.

Solution 3:

you are using the background property, android will stretch your image depending on the device resoulution in dpi (ldpi, mdpi, hdpi and xhdpi screens), if you put your image in drawable-mdpi folder, your image will stretch according to this coefficient

enter image description here

Post a Comment for "Android : My Button Image Is Enlarged In The App?"