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

标签 android

我有一个问题,我需要在 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/

相关文章:

android - 无法构建项目 ionic ios 和 android

Android处理图像处理时的内存不足异常

android - 设计一个漂亮的 Android 应用程序

android - "ionic cordova prepare android"继续尝试安装 iOS 插件导致在 Ubuntu 16.04 上构建失败

android - react-native 构建 DependencyGraph 时出错

java - 手电筒无法打开

android - 如何在Kotlin中实现View Pager同一个Fragment?

android - 通知,服务器到客户端

Android - 在横向和纵向模式之间切换使 Intent 失去值(value)

android - 想要在 Android 上的 Delphi 应用程序中保持屏幕开启