开发者

Android align two buttons

开发者 https://www.devze.com 2023-02-08 13:54 出处:网络
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:

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="N开发者_StackOverflow社区ames" 
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>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消