2011-02-05 82 views
4

我有两个彼此相邻的按钮。我希望它们具有相同的尺寸并填充屏幕的整个宽度。我一直在试图与此代码: (它的RelativeLayout的,如果该事项)Android对齐两个按钮

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

回答

25

裹绕按钮的LinearLayout中?那么你可以使用填充来调整确切的位置,如果需要

<?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> 
+1

这是一个美丽的解决方案。完全按照需要工作。 – jbranchaud 2011-03-18 02:27:01