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.
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 .
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With