Разделить экран на две части

#android

#Android

Вопрос:

Я пытаюсь разделить свой макет на две половины.Когда я пытаюсь layout_weight, in разбивает его на две горизонтальные половины.Как мне разделить макет на две вертикальные половины.

           <?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>
  

Ответ №1:

Используйте ‘orientation =»vertical»‘ во вложенном макете и применяйте свои веса к дочерним элементам, таким как:

 <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"
    .../>