我有一个线性布局,填充父级的布局参数和换行内容。方向是水平的。Android:完全对齐两个按钮
在线性布局里面我有两个按钮。它们在左侧彼此相邻。
我希望两个按钮能够“充分证明”。换句话说,我希望每个按钮占据线性布局的一半宽度。
任何人都可以帮忙吗?
我有一个线性布局,填充父级的布局参数和换行内容。方向是水平的。Android:完全对齐两个按钮
在线性布局里面我有两个按钮。它们在左侧彼此相邻。
我希望两个按钮能够“充分证明”。换句话说,我希望每个按钮占据线性布局的一半宽度。
任何人都可以帮忙吗?
使用权,如:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="Button1"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Button2"
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
定义设置的每个子女的父或母,权重总和的一半
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:text="Button1"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Button2"
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
你定义不需要设置weightSum。你可以添加它,但没有必要。事实上:“weightSum定义了最大权重和,如果未指定,则通过添加所有子项的layout_weight来计算总和” – Frame91
非常感谢!真的很简单:) – Trevor