I want to make a LinearLayout like this by percent
each rectangle is a LinearLayout
is that possible to make and how ?
I want to make a LinearLayout like this by percent
each rectangle is a LinearLayout
is that possible to make and how ?
Check this sample xml...this will helpfull to understand the weightSum
and layout_weight
in the LinearLayout
Check this SO
<?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"
android:weightSum="100" >
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Button20" />
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Button20" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Button20" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="Button40" />
Use this One:
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="20%" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="20%" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="20%" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="40%" />
</LinearLayout>
You need to make each cell
's width equal to match_parent
and then play with the layout_weight
value for each child. As layout_weight specifies size ratio between multiple elements, i.e.