luc*_*uca 50 layout user-interface android
如何将2个按钮并排放置,以便它们占据所有宽度,两者之间有一点空间.
我想到了一个水平线性布局,2个子线性布局设置为匹配父级和重量1,每个都包含按钮..是否有更简单的方法?这可以用相对布局来完成吗?
谢谢!
2re*_*d13 105
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/Button02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:text="Apply">
</Button>
<Button
android:id="@+id/Button03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel">
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果您希望2个按钮占据所有宽度并且按钮具有相同的宽度,则必须在2个按钮中更改属性:
android:layout_width="wrap_content" 至 android:layout_width="match_parent"
因为如果你有一个带有长文本的按钮而另一个带有短文本的按钮,那么带有长文本的按钮会占用更多的空间.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="button1"
android:id="@+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="button2"
android:id="@+id/button2" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72957 次 |
| 最近记录: |