Reputation: 172
I have the following layouts:
And it looks pretty much like this:
I want these two toggle buttons to be on the very left and right bottom like this:
I'm not sure how to this. Thanks !
Upvotes: 0
Views: 1637
Reputation: 511
Please, don't use RelativeLayouts. Learning to do what you want with LinearLayouts will make a big difference in the long run.
The solution is simple. Create a "wrapper" for your toggle buttons. (LinearLayout for each one), then use Weight to distribute the the layouts evenly from left to right. Float the second toggle button to the right using the Gravity and you're golden:
To make sure that the toggle buttons float all the way to the bottom, enclose your grid of buttons inside a single LinearLayout and set the weight for that layout to 1. This will make your first layout will as much of the screen as possible. (Minus the size of the new LinearLayout you're about to make for your toggle buttons). This floats the code below to the bottom of the screen.
Here's some rough XML code for you:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="ToggleButton" />
</LinearLayout>
Upvotes: 0
Reputation: 9700
Try as below using LinearLayout
....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
OR, using RelativeLayout
as below...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
Upvotes: 0
Reputation: 2091
Use a RelativeLayout with two LinearLayout inside.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
/*Top buttons*/
</LinearLayout>
/*Align bottom right with alignParent property*/
<LinearLayout
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
/*Toggle button right*/
</LinearLayout>
/*Align bottom leftwith alignParent property*/
<LinearLayout
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
/*Toggle button left*/
</LinearLayout>
</RelativeLayout>
Upvotes: 0
Reputation: 3962
I'd advice a RelativeLayout, where you put your two toggle buttons (with alignParentBottom, alignParentLeft and alignParentRight), and then a GridLayout instead of multiple LinearLayouts for all your other buttons.
Upvotes: 0
Reputation: 8836
use relative as outer layout and put your linearlayout inside it.
<RelativeLayout>
<LinearLayout
marginLeft
marginRight
/>
<ToggleButton>
alignParentBottom="true"
alignParentLeft ="true"
</ToggleButton>
<ToggleButton>
alignParentBottom="true"
alignParentRight="true"
</ToggleButton>
</RelativeLayout>
Upvotes: 2