How to center multiple Views together using ConstraintLayout?

前端 未结 5 496
野的像风
野的像风 2021-02-01 12:17

Background

Google has announced a new layout called \"ConstraintLayout\" that\'s supposed to be the ultimate layout, that could replace all of the layouts while stayin

5条回答
  •  温柔的废话
    2021-02-01 12:29

    Set app:layout_constraintVertical_bias="0.5" to the views that need to be centered vertically, bias attribute only works if you specify the constraints for the boundaries (e.g. top and bottom for vertical bias, left and right for horizontal bias)

    An example:

    
    
        
    
    
    

    Got it working in my layout here: https://github.com/hidroh/tldroid/blob/master/app/src/main/res/layout/activity_main.xml, pretty much similar layout, though I position things at 1/3rd of screen height.

提交回复
热议问题