线性布局下,如何最左或者最右

来源:互联网 发布:小世界网络 聚类系数 编辑:程序博客网 时间:2024/05/16 08:51


线性布局下,如何在一行中,一个按钮位于最左边,一个最右边?

这个如果用RelativeLayout控制就很容易,要是用LinearLayout也不是不可能。思路就是在中间放置一个控件,让其透明,并设置weight为1.0。
下面代码已经测试,仅供参考:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal">    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" />    <Button        android:alpha="0"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1.0" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></LinearLayout>




2 9
原创粉丝点击