我有一个问题,我需要在 android 布局中放置 3 个按钮,但是:
- 他们应该排成一排
- 它们都应该是显示宽度的 33.3%
我用表格和堆栈布局尝试了一些东西,但没能让它与宽度一起工作。
请帮帮我
最佳答案
使用 LinearLayout 作为根,然后为每个按钮赋予属性 android:layout_weight="1"
- 这将使它们都具有相同的权重,并占用空间。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dip"
android:orientation="horizontal" >
<Button
android:id="@+id/rvButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/rvButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/rvButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
关于android - 如何在 android 布局中添加 3 个按钮并让每个按钮的宽度为 33.3%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13181849/