您的位置:首页 > 其它

LinearLayout中的控件两端对齐

2015-05-09 13:53 786 查看
在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>

<?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按钮 两端对齐
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: