How to get ImageButton in Android to automatically scale based on screen density?

I have an image placed on ImageButtonthat looks good on the mdpi ( medium-dpi ) screen . However, when the device has an hdpi screen ( high resolution per inch ), the image is still pixel-pixel, which looks little on the device screen.

How to make the image (and therefore ImageButton) scale based on pixels independent of density ( dp or dip ) instead of pixels?

+3
source share
4 answers

, 9- - . (drawable-hdpi, drawable-mdpi ..) , .

9- Multiple Resolutions SDK SDK. 9- PNG ldpi, mdpi hdpi.

+4
android:scaleType="fitXY"

:

fitStart
fitCenter
fitEnd
center
cenerCrop
centerInside
matrix

, PNG .

+8

IMHO NinePatchDrawable , tool, (//...) . . ( "NinePatchDrawable" ), NinePatchDrawable.

NinePatchDrawable - , Android . NinePatch - , Android - . NinePatch PNG-, 1- . .9.png, res/drawable/ .

+5

, ?

android:layout_width="300dip" 
android:layout_height="50dip"
+3

Source: https://habr.com/ru/post/1728148/


All Articles