http://hi.baidu.com/mikenoodle/item/ba2c5f3aff1333352e20c4bf
在android中的控件LinearLayout 中的android:gravity="center" 属性,要么是居左、居右、居中对齐,不能达到双控件 两端对齐,
要实现两端对齐方式,要采用 中间增加一个控件的方式实现 ,并设置属性weight=1。
具体的布局文件如下:
Xml代码
-
<?xml version="1.0″ encoding="utf-8″?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:orientation="horizontal" >
-
-
<Button
-
android:id="@+id/Button01"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="button01" >
-
</Button>
-
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_weight="1" />
-
-
<Button
-
android:id="@+id/Button02"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="button02" >
-
</Button>
-
-
</LinearLayout>
效果如图:
实现两个button按钮 两端对齐