I am learning about the difference between LinearLayout
and RelativeLayout
and am confused about the best way to solve my specific problem. I want to have 4 buttons fill a screen, each with some different action. After having trouble with RelativeLayout
, I was recommended to switch to LinearLayout
by this SO thread. Using a nested LinearLayout
and the android:weight
value, I got a solution that does work properly. However, now I get the warning: "Nested weights are bad for performance." I propmtly looked that up on SO and found this article, telling me to switch back to RelativeLayout
.
What's the right answer? Is there a good way to have objects fill an area like this in RelativeLayout
?
This is my current code. Excuse the extra stuff, not sure what to leave in and what to just take out.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motherStack"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/rowOne"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
<Button
android:id="@+id/redButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/red_button_text"
android:textColor="@color/RED" />
<Button
android:id="@+id/blueButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/blue_button_text"
android:textColor="@color/BLUE" />
</LinearLayout>
<LinearLayout
android:id="@+id/rowTwo"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
<Button
android:id="@+id/greenButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/green_button_text"
android:textColor="@color/GREEN" />
<Button
android:id="@+id/yellowButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/yellow_button_text"
android:textColor="@color/YELLOW" />
</LinearLayout>
I would post an image but I just joined and have no reputation. :(