Divide the application screen into two layouts

7

I want to split the screen in half.

I have two LinearLayout of the same size, but it seems that the only way to do this is to place the size in the android:layout_height=<tamanho> property?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_id"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp"
tools:context=".MyActivity">


  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
  </LinearLayout>

  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
  </LinearLayout>
</LinearLayout>

This is my layout.xml , I want to leave the two LinearLayout internal with the same height.

    
asked by anonymous 19.12.2014 / 13:27

1 answer

12

You can work this way using the weight (Weight) attribute.

Note the code below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1" >  //Peso total do Layout


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"> //Esse Layout pesa 50% do Layout total

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"> //Esse Layout pesa 50% do Layout total

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

</LinearLayout>


</LinearLayout>

In% main%, it has been defined that LinearLayout is 1 and in weight more internal, it has been defined that each is half the weight of the main Layout. (I put the two LinearLayout 's just to better visualize the result)

Notice the result:

    
19.12.2014 / 13:45