Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: align Button and ToggleButton horizontally in LinearLayout or RelativeLayout

if I try to align the toggle inbetween two buttons within a LinearLayout, I always come up with something where the toggle is slightly misaligned by about 2px to the bottom. I tried a RelativeLayout and also android:layout_gravity=""center_vertical".

Thanx, Huck

like image 220
Huck Finn Avatar asked Feb 06 '11 17:02

Huck Finn


2 Answers

I just added android:layout_gravity=""center_vertical" to both controls and the desaligment dissapears. although I am using SDK 2.3.3

like image 101
Igor Zelaya Avatar answered Sep 18 '22 16:09

Igor Zelaya


Like the guy above said : This works perfectly..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button  android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="center_vertical" />   

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:layout_gravity="center_vertical" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" 
android:layout_gravity="center_vertical"/>

</LinearLayout>
like image 37
carora3 Avatar answered Sep 18 '22 16:09

carora3