relativelayout - How to make 2 horizontal buttons to fill relative layout equally? -
the corresponding xml layout:
<relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/buttons_holder" android:layout_below="@+id/list_holder" android:layout_alignparentbottom="true"> <imagebutton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/previous_button" android:src="@android:drawable/ic_media_previous" android:layout_alignparentleft="true" android:minwidth="150dp" android:layout_alignparentbottom="false" android:layout_alignparentright="false" android:layout_alignparenttop="false" android:scaletype="fitend" /> <imagebutton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/forward_button" android:src="@android:drawable/ic_media_next" android:layout_alignparentright="true" android:minwidth="150dp" android:scaletype="fitstart" android:layout_alignwithparentifmissing="false" /> </relativelayout>
i can change button's width setting
minwidth = 200dp maxwidth = 200dp
so button occupy fixed space inside relative layout
but want 'right way' - using gravity, but there no gravity button - relative layout holds these 2 buttons
how make 2 buttons occupy equal space inside rel layout?
you can use @onik's suggestion. if want use relativelayout then
- place dummy view in center of relativelayout
- put button1 toleft of dummy view
- put button2 toright of dummy view
sample code:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <imagebutton android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toleftof="@+id/dummy" /> <view android:id="@+id/dummy" android:layout_width="1dp" android:layout_height="1dp" android:layout_centerhorizontal="true" /> <imagebutton android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/dummy" /> </relativelayout>
Comments
Post a Comment