How to do it? (Image link)
I was wondering how to get this result:
http://img718.imageshack.us/img718/6173/screenshot20100411at126.png
This is what I tried:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:orientation="horizontal"
android:layout_weight="0">
<Button android:id="@+id/btn_cancel"
android:text="@string/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:gravity="left"
/>
<Button android:id="@+id/btn_save"
android:text="@string/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:layout_toRightOf="@id/btn_cancel"
android:gravity="right"/>
</RelativeLayout>
I tried to play with the layout_width properties and tweak them to fill the parents with both of them, but didn't work if anyone has an idea ... Thanks!
source to share
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="#CCCCCC"
android:orientation="horizontal">
<Button android:id="@+id/btn_cancel"
android:text="@string/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_weight="1"/>
<Button android:id="@+id/btn_save"
android:text="@string/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
The triumph in LinearLayout to get two widgets to occupy the same space is to install layout_width="fill_parent"
on both of them and then install layout_weight="1"
on both of them. Setting both fill_parent and layout_weight will show LinearLayout to split all available space between them.
Also, use dip
instead px
. dip
independent of the screen size and will look better on different screen sizes.
source to share