Constraint Layout Vertical Align Center

后端 未结 7 990
醉梦人生
醉梦人生 2020-12-13 05:20

How to vertically align and center objects in constraint layout? It is possible to align vertically or horizontally but I have not found a way to center at the same time bes

7条回答
  •  死守一世寂寞
    2020-12-13 05:56

    I also had a requirement something similar to it. I wanted to have a container in the center of the screen and inside the container there are many views. Following is the xml layout code. Here i'm using nested constraint layout to create container in the center of the screen.

        
    
    
    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
    

    Here is the screenshot of the layout

    Other solution is to remove the nested constraint layout and add constraint_vertical_bias = 0.5 attribute to the top element in the center of layout. I think this is called as chaining of views.

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    Here is the screenshot of the layout

提交回复
热议问题