Friday, November 1, 2019

How to linearlayout orientation horizontal and vertical Android

Of course, if we do not apply the above method set to 0dp, directly use wrap_content and match_parent, then we must parse the weight attribute, divided into two cases, wrap_content and match_parent! Also look at the LinearLayout orientation is horizontal or vertical, which determines which direction is proportionally divided
1) wrap_content is relatively simple, directly proportional.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <TextView
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="one"
        android:textSize="30sp"
        android:background="#98FB98"
        />
    <TextView
        android:layout_weight="2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="two"
        android:textSize="30sp"
        android:background="#FFFF00"
        />
    <TextView
        android:layout_weight="3"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="three"
        android:textSize="30sp"
        android:background="#FF00FF"
        />
</LinearLayout>  
Result  linearlayout horizontal android
How to linearlayout orientation horizontal and vertical Android
2. Linearlayout match_parent horizontal android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    xmlns:tools="http://schemas.android.com/tools"   
    android:id="@+id/LinearLayout1"   
    android:layout_width="match_parent"   
    android:layout_height="match_parent" >   
   
    <TextView   
        android:layout_weight="1"   
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"   
        android:text="one"   
        android:background="#98FB98"   
     />   
     <TextView   
        android:layout_weight="2"   
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"   
        android:text="two"   
        android:background="#FFFF00"   
     />   
     <TextView   
        android:layout_weight="3"   
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"   
        android:text="three"   
        android:background="#FF00FF"   
     />   
   
</LinearLayout> 
Result below:

No comments:

Post a Comment