我需要把3个按钮放在 android 布局中。
需要实现:
我使用一个表格和 stack布局,但是不知道如何设置设置宽度,请大家帮忙。
使用一个 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"
/>
使用下面的代码:
<LinearLayout
android:layout_with="fill_parent"
android:layout_height="warp_content"
android:orientation="horizontal"
android_weight_sum="3">
<View
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=1 />
<View
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=1 />
<View
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=1 />
</LinearLayout>
LinearLayout 一共有3个 view,里面的每一个 view占据 1/3 的空间。
是一行显示3个button,3个平分宽带么 可以用android:layout_weight="" 来控制控件的权重试试