Two buttons matching parent side by side in Android (xml)
I am currently toying around with android and making a little bit of a test app just to try coding one. I开发者_StackOverflow中文版'm sure there's an easy way to do this but i can't figure it out. I want two buttons to be on the bottom of the screen. But, i want one to be on the left side, and one on the right side, with space in the middle.
Thanks for the help
Like this perhaps?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id"@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Left"/>
<Button
android:id"@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
You need to give android:layout_alignParentLeft="true" to align left and android:layout_alignParentRight="true" to align right.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id"@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Left"/>
<Button
android:id"@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
You can do that using either LinearLayout
, TableLayout
or RelativeLayout
. Try it... it's not that hard.
Create a linear layout (inside your linerlayout which is created by default when your creating layout)
Edit your new linear layout
android:layout_gravity="bottom" android:orientation="horizontal" android:gravity="center"
Add two buttons inside linearlayout (add text/size also)
Optional: add both button margin_layout: 10dip
android:layout_margin="10dip"
That should do.
精彩评论