How to change the size of image lager than screen

Issue

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?

Solution

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

Answered By – Justin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published