Resize image by Android screen resolution

I have a background image in the body. I want to achieve:

1). Calculate the visitor screen resolution.
2) - based on this resolution, I want to resize the background image.

I know the screen resolution is equal

Display display = getWindowManager().getDefaultDisplay(); width_screen = display.getWidth(); height_screen = display.getHeight(); 

But I do not know how to resize images to fit the user's screen resolution.

Can anyone help? Thanks..

+6
source share
2 answers

Put the ImageView in your layout file and install

  android:layout_width="match_parent" android:layout_height="match_parent" 

If you want to keep aspect:

  android:scaleType="centerInside" 

If you don't care about aspect ratio, use:

  android:scaleType="fitXY" 
+6
source

You may need to write a custom view for this. Override the onDraw method to copy the bitmap as many times as needed.

0
source

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


All Articles