How to set a maximum height with wrap content in android?

前端 未结 7 2219
你的背包
你的背包 2020-12-09 02:01

In android, how can you create a scroll view that\'s got a max height, and wrap contents, basically it wraps the content vertically, but has a maximum height?

I trie

7条回答
  •  时光说笑
    2020-12-09 02:39

    It can be done by wrapping the view into ConstraintLayout and using layout_constraintHeight_max attribute.

    
    
        
    
            ...
    
        
    
    
    

    In the example above, the parent ConstraintLayout height is limited to 200dp, and the child ScrollView height wraps the content till it's less than 200dp. Note that app:layout_constraintVertical_bias="0" aligns the child ScrollView at the top of the parent, otherwise it will be centered.

提交回复
热议问题