Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android align two buttons

i have two buttons next to each other. I want them to be the same size and fill the whole width of the screen. I've been trying with this code: (It's relativelayout, if that matters)

<Button android:text="Names" 
android:id="@+id/Button01" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
<Button android:text="Dates" 
android:id="@+id/Button02" 
android:layout_toRightOf="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
like image 286
erdomester Avatar asked Nov 28 '22 22:11

erdomester


1 Answers

Wrap a LinearLayout around the buttons? then you can use padding to adjust the exact location if needed

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<Button android:text="Names" 
android:id="@+id/Button01" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
<Button android:text="Dates" 
android:id="@+id/Button02" 
android:layout_toRightOf="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
</LinearLayout>
like image 187
Linora Avatar answered Nov 30 '22 10:11

Linora