Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split the screen with two equal LinearLayouts?

Wanna to split a screen for my app with two LinearLayouts. What parameters should I use to make exact splitting in two equal parts - first LinearLayout on the top and the second one is just under it.

like image 606
Eugene Avatar asked Aug 06 '10 14:08

Eugene


People also ask

How do you divide linear layout in equal parts?

first Remove the android:layout_weight="1" from LinearLayout. then set android:layout_width="0dp" for TextView & ImageButton. and then set android:layout_weight="0.75" for TextView and set android:layout_weight="0.25" for ImageButton .


2 Answers

Use the layout_weight attribute. The layout will roughly look like this:

<LinearLayout android:orientation="horizontal"     android:layout_height="fill_parent"      android:layout_width="fill_parent">      <LinearLayout          android:layout_weight="1"          android:layout_height="fill_parent"          android:layout_width="0dp"/>      <LinearLayout          android:layout_weight="1"          android:layout_height="fill_parent"          android:layout_width="0dp"/>  </LinearLayout> 
like image 57
Konstantin Burov Avatar answered Sep 28 '22 08:09

Konstantin Burov


I am answering this question after 4-5 years but best practices to do this as below

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">     <LinearLayout       android:id="@+id/firstLayout"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:layout_toLeftOf="@+id/secondView"       android:orientation="vertical"></LinearLayout>     <View       android:id="@+id/secondView"       android:layout_width="0dp"       android:layout_height="match_parent"       android:layout_centerHorizontal="true" />     <LinearLayout       android:id="@+id/thirdLayout"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:layout_toRightOf="@+id/secondView"       android:orientation="vertical"></LinearLayout> </RelativeLayout> 

This is right approach as use of layout_weight is always heavy for UI operations. Splitting Layout equally using LinearLayout is not good practice

like image 40
silwar Avatar answered Sep 28 '22 08:09

silwar