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

前端 未结 25 1807
孤独总比滥情好
孤独总比滥情好 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:29

    To anyone else having this particular issue. You have an ImageView that you want to have a width of fill_parent and a height scaled proportionately:

    Add these two attributes to your ImageView:

    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    

    And set the ImageView width to fill_parent and height to wrap_content.

    Also, if you don't want your image to be cropped, try this:

     android:adjustViewBounds="true"
     android:layout_centerInParent="true"
    
    0 讨论(0)
提交回复
热议问题