如何在Android布局中添加3个按钮,让每个按钮的宽度为33.3%?

gur*_*gui 1 android

我有一个问题,我需要在Android布局中放置3个按钮,但是:

  • 它们应该都在一排
  • 它们应该都是显示宽度的33.3%宽度

我尝试了一些表和堆栈布局的东西,但没有设法让它与宽度一起工作.

请帮我

xdu*_*ine 5

使用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"
    />
Run Code Online (Sandbox Code Playgroud)