How to scale an Image in ImageView to keep the aspect ratio

前端 未结 25 1816
孤独总比滥情好
孤独总比滥情好 2020-11-22 04:59

In Android, I defined an ImageView\'s layout_width to be fill_parent (which takes up the full width of the phone).

If the imag

25条回答
  •  渐次进展
    2020-11-22 05:06

    I have an image smaller than the screen. To have it stretched proportionally to the max and centered in the view I had to use the following code:

    
    

    Have in mind though, that if you have a relative layout and have some elements set to be above or below the ImageView, they will be most likely overlapped by the image.

提交回复
热议问题