Split a layout into 2 with different percentages

2

I wanted to know how I'd do to split a layout into 2 with 70/30 percent. I've got a way to split, but that way is not optimized for all devices.

    
asked by anonymous 27.02.2018 / 17:51

2 answers

2

Use a LinearLayout and refer to the android: layout_weight attribute for define, proportionally , the space each View occupies:

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

        <SeuLayoutDaEsquerda
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight="70"/>

        <SeuLayoutDaDireita
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight="30"/>

</LinearLayout>

The sum of the values indicated in the android:layout_weight attribute corresponds to 100% of the total space. In the present case 100% corresponds to 100 (could be another value).

So, by indicating android:layout_weight="70" in the first, we are saying that it should occupy 70 parts (70/100) of the total space.

Similarly, by specifying android:layout_weight="30" in the second, we say that the space to be occupied by it must be 30 parts (30/100) of the total space.

Note: Using the android:layout_weight attribute requires that, according to the LinearLayout orientation, the android:layout_width or android:layout_height is set to "0dp".

    
27.02.2018 / 18:07
1

You can use the layout_weight (weight) attribute in each view , assigning the value 0.7 representing 70% and 0.3 representing 30%. Here's an example:

<?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="horizontal" >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.7">

        <!--seu conteúdo aqui-->

    </LinearLayout>
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3">

      <!--seu conteúdo aqui-->

    </LinearLayout>
</LinearLayout>
    
27.02.2018 / 18:04