How to align ImageView to the bottom, fill its width and height, and keep its aspect ratio?

后端 未结 6 2014
攒了一身酷
攒了一身酷 2021-02-05 11:36

Background

There are various XML attributes for ImageView to scale its content , and various layout views that allow to place views and set their sizes.

Howeve

6条回答
  •  無奈伤痛
    2021-02-05 12:36

    You need a combination of three attributes:

    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
    

    The adjustViewBounds attribute is needed because ImageView measures itself to match the original dimensions of the drawable by default, without regard to any scaling performed according to the scale type.

提交回复
热议问题