Home > Mobile >  How to change the size of image lager than screen
How to change the size of image lager than screen

Time:07-26

Im trying to change an image lager than the screen so that the image partly(boundary parts) gets out of the screen. The purpose Im doing this is to make the whole screen filled with the image. I tried simply changing the height and width bigger than the height and width of screen which I got but it didn't work well. I used code below to get the size of the screen.

val displayMetrics = DisplayMetrics()
    windowManager.defaultDisplay.getMetrics(displayMetrics)
    val height = displayMetrics.heightPixels
    val width = displayMetrics.widthPixels

How should I do for this?

CodePudding user response:

If you want to fill the image to entire screen like a zoomed view, I think you can try image loading libraries like Picasso or Glide to crop the image to fit it inside the layout and also it will handle the caching for large sized images.

For Picasso you can try something like this

Picasso.with(this).load(R.drawable.image).centerCrop().into(imageView);

CodePudding user response:

In the xml match the height and width of the image to parent and change the scaleType attribute to centerCrop -> android:scaleType="centerCrop"

  • Related