Split screen in two

2019-09-05 06:05发布

I am trying to split my layout into two halves.When I try layout_weight,in splits it into two horizontal halves.How do i split the layout into two vertical halves.

          <?xml version="1.0" encoding="utf-8"?>

android:id="@+id/linearLayout123" android:layout_width="fill_parent"
android:layout_height="fill_parent">




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_weight="1" 
                 android:layout_gravity="top" 
                 android:id="@+id/linearLayout12"
    android:layout_width="fill_parent" 
                 android:layout_height="fill_parent">


 <Button android:id="@+id/button1"            
               android:layout_width="wrap_content"                                          

               android:layout_height="wrap_content"           
                android:text="Hello, I am a Button" />



      </LinearLayout>



<LinearLayout android:layout_weight="1"
    android:layout_gravity="bottom" android:id="@+id/linearLayout1"
    android:layout_width="fill_parent" android:layout_height="fill_parent">


           <TextView 
            android:id="@+id/text2"              
            android:layout_width="wrap_content"             
            android:layout_height="wrap_content"              
            android:text="Hello, I am a TextView" />

       </LinearLayout>

      </LinearLayout>

标签: android
1条回答
何必那么认真
2楼-- · 2019-09-05 06:44

Use 'orientation="vertical"' in the enclosing layout, and apply your weights to the children such as:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_gravity="fill"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:weightSum="1.0"
    android:orientation="vertical"
    android:padding="5dp"> 

<TopChildView android:layout_height="0dp"
    android:layout_weight="0.5"
    .../>

<BottomChildView android:layout_height="0dp"
    android:layout_weight="0.5"
    .../>

查看更多
登录 后发表回答