How to set maxHeight over DimensionRatio with ConstraintLayout?

后端 未结 3 939
粉色の甜心
粉色の甜心 2021-01-05 14:41

I\'m trying to display an image centered in parent with a dimension ratio of 1220:1000 AND a maximum height of 300dp (to keep the image small even with large screen)

3条回答
  •  醉话见心
    2021-01-05 15:07

    If you want to enforce max_height and keep the dimension ratio at the same time, you need to constrain the width based on height. You can achieve that by adding W to your ratio:

    app:layout_constraintDimensionRatio="W,1220:1000"

    This will constrain the height first and then set the width accordingly to satisfy the ratio.

    More info on how this dimension ratio works can be found in the documentation.

提交回复
热议问题