How to set maxHeight over DimensionRatio with ConstraintLayout?

后端 未结 3 931
粉色の甜心
粉色の甜心 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:16

    If you want to maximize the area with a dimension ratio and a max height, but you don't know if width or height is going to be adjusted, better don't to use layout_constraintDimensionRatio + layout_constraintHeight_max. They don't work well together.

    Here I put my solution in the case you have an image 16:9 which will use full width while max height is not yet reached, otherwise it will respect max height, and width will be adjusted:

    
    
            
            
    
            
    
    

    I used a custom ImageView I had in my gist which adjusts to aspect ratio, in order to avoid using layout_constraintDimensionRatio which causes the problem together with layout_constraintHeight_max

提交回复
热议问题