Saturday, November 28, 2015

Use Weight in Linear Layout Android

use weight for equal child of layout. margin and padding unable to set equal child because when multi screen support and margin and padding set fix, but in weight they remains same in all layout.

In Linear Layout need orientation horizontal and vertical.


XML for Linear layout weight.

<LinearLayout    
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="50dp" 
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:orientation="horizontal">

    <TextView       
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:text="FIRST"   
       android:gravity="center"  
       android:textSize="20sp"  
       android:textColor="#000000"/>

    <TextView  
      android:layout_width="0dp"   
      android:layout_weight="1"    
      android:layout_height="wrap_content"  
      android:text="SECOND"   
      android:gravity="center"   
      android:layout_marginLeft="20dp"
      android:textSize="20sp"   
     android:textColor="#000000"/>

</LinearLayout>

No comments :

Post a Comment