Use Layout Weights. Keep in mind that it is important to set layout_width
as 0dp
on children to make it work as intended.
on parent layout:
weightSum
of parent Layout as 1
(android:weightSum="1"
)on the child layout:
layout_width
as 0dp
(android:layout_width="0dp"
) layout_weight
as 0.5
[half of weight sum fr equal two] (android:layout_weight="0.5"
)weightSum
3layout_weight
: 1weightSum
1layout_weight
: 0.25To split layout to n equal parts:
- parent:
weightSum
n- child:
layout_weight
: 1
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView .. />
<EditText .../>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView ../>
<EditText ../>
</LinearLayout>
</LinearLayout>