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 :
Solution 1:
Are you supplying bouton_back
in your resources using multiple densities? Using dp
units to size your button isn't sufficient; you must also provide multiple sizes of your images:
ldpi: 120dpi mdpi: 160dpi hdpi: 240dpi xhdpi: 320dpi The conversion formula is as follows:
px = dp * (dpi / 160 )
Copy 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.75 hdpi = mdpi * 1.5 xhdpi = mdpi * 2.0
Copy 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
Post a Comment for "Android : My Button Image Is Enlarged In The App?"