Restrict width in ConstraintLayout by another view

前端 未结 1 593
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 02:16

Is there a possibility (in ConstraintLayout) to let a view grow only as long as there is space for another view at his right?

The use case is to have a

1条回答
  •  萌比男神i
    2021-02-05 02:40

    yes you can by using match_constraint (0dp) which equal to match_parent for other layout, so by using match_constraint we set weight for first view which will occupies all available space also add

    app:layout_constraintWidth_default="wrap"
    

    to apply default width behavior as wrap_content

    here is code with change

    
    
    
            
    
            
    
        
    

    got some explanation from site

    Better view dimension controls

    The new available behaviors when a dimension is set to 0dp (MATCH_CONSTRAINT). As before, both endpoints (left/right or top/bottom) need to be connected to targets.

    layout_constraintWidth_default = spread (default, similar to the previous behavior) layout_constraintWidth_default = wrap layout_constraintHeight_default = spread layout_constraintHeight_default = wrap

    Wrap provides a significant new behaviour, with the widget resizing as if wrap_content was used, but limited by the connected constraints. A widget will thus not grow beyond the endpoints.

    http://tools.android.com/recent/constraintlayoutbeta5isnowavailable

    0 讨论(0)
提交回复
热议问题