线性布局下,如何在一行中,一个按钮位于最左边,一个最右边?
这个如果用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>