How to split the screen with two equal LinearLayouts?

前端 未结 6 1356
轻奢々
轻奢々 2020-12-04 11:08

Wanna to split a screen for my app with two LinearLayouts. What parameters should I use to make exact splitting in two equal parts - first LinearLayout on the top and the se

6条回答
  •  孤城傲影
    2020-12-04 12:10

    To Split a layout to equal parts

    Use Layout Weights. Keep in mind that it is important to set layout_width as 0dp on children to make it work as intended.

    on parent layout:

    1. Set weightSum of parent Layout as 1 (android:weightSum="1")

    on the child layout:

    1. Set layout_width as 0dp (android:layout_width="0dp")
    2. Set layout_weight as 0.5 [half of weight sum fr equal two] (android:layout_weight="0.5")


    To split layout to three equal parts:

    • parent: weightSum 3
    • child: layout_weight: 1

    To split layout to four equal parts:

    • parent: weightSum 1
    • child: layout_weight: 0.25

    To split layout to n equal parts:

    • parent: weightSum n
    • child: layout_weight: 1


    Below is an example layout for splitting layout to two equal parts.

    
    
        
    
            
    
            
    
        
    
        
    
            
    
            
    
        
    
    
    

提交回复
热议问题