You must refer to the weightSum attribute of the linear layout. Then the attributes layout_weight , layout_height and layout_width internal views. This is all you need to divide the layout into any ratio.
If you want to split the layout into two parts of the same size, you must set the layout_width attributes to 0dp both layouts and layout_weight to 1 inside the main layout. Then set weightSum to 2 parent layout.
The same concept can be applied to divide the layout into any ratio. Set all internal layout_weight values layout_weight sum of weightSum . Then set layout_width or layout_height to 0dp according to the orientation you want to split. Here is a mock solution for this question.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" tools:context=".MainActivity" android:weightSum="2"> <fragment android:id="@+id/mainFragment" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"> </fragment> <fragment android:id="@+id/detailFragment" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"> </fragment> </LinearLayout>
here is an example to divide the linear alignment by 1, 3, 2 vertically.
<?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:weightSum="6"> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@android:color/white"> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3" android:background="@android:color/black"> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:background="@android:color/white"> </RelativeLayout> </LinearLayout>
source share