Android layout Android:两个按钮完全对齐
我有一个线性布局,布局参数为fill parent和wrap content。方向是水平的 在线性布局中,我有两个按钮。它们在左手边相邻出现 我希望这两个按钮“完全合理”。换句话说,我希望每个按钮占据线性布局的一半宽度 有人能帮忙吗?使用以下重量:Android layout Android:两个按钮完全对齐,android-layout,Android Layout,我有一个线性布局,布局参数为fill parent和wrap content。方向是水平的 在线性布局中,我有两个按钮。它们在左手边相邻出现 我希望这两个按钮“完全合理”。换句话说,我希望每个按钮占据线性布局的一半宽度 有人能帮忙吗?使用以下重量: <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&
<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定义了最大权重和。如果未指定,则通过添加所有子项的布局权重来计算权重和。”非常感谢!非常简单:)