Tuesday, September 7, 2010

Android: 2 view elements side by side

In my Android application, I wanted to display 2 spinners, side by side (50% of the width each).
I didn't want to use width = "100px" for example. I wanted to be relative as much as possible.
So here is what I did:


android:layout_alignParentBottom="true" android:layout_width="fill_parent">
android:layout_height="wrap_content" android:weightSum="100">

android:id="@+id/btnBack"
android:layout_height="wrap_content"
android:text="@string/back"
style="?button"
android:layout_weight="50">


android:id="@+id/btnMap"
android:layout_height="wrap_content"
android:text="@string/map"
style="?button"
android:layout_weight="50">





***WARNING*** XML tags are case sensitive. In my example above, I don't know why it's display in lower case... Please use TableLayout, TableRow and Button!

I created a tableLayout with 1 tablerow. In each tablerow I added 2 buttons.
I set the attribute weightsum="100" to the row. And for each element of the row,I set layout_weight="50".
And that's it!

1 comment:

shruths said...

The last few lines worked...thanks a lot......ur awesome...:D