需要均匀分布的按钮行

2023-12-21

我尝试使用 3 行和 4 列将所有按钮水平均匀地隔开,但失败了。垂直的就好。

下面是 3 种不同的按钮间隔尝试,我的 3 行每行 1 种。第一行拉伸图形(这是不需要的),第二行不拉伸但没有间距(图形之间需要间距),而第三行拉伸没有任何间距。请帮我将它们均匀地分开。同一个网站上其他人的解决方案不起作用。我应该尝试使用桌子吗?

视觉总结=不拉伸图形: 我想要| x x x x | 而不是 | xxx |

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>
</LinearLayout>

<LinearLayout
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/row3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal"
    android:weightSum="1" >

    <Button
        android:id="@+id/c1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />
</LinearLayout>

</LinearLayout>

尝试这个:

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>

在第一行尝试这个。可以对所有行进行类似的操作,

因此,除非您不希望图像被拉伸,否则您需要将它们放在布局中。这样做你将管理间距,并且可绘制的看起来会很好。如果拉伸按钮,则可绘制对象也会相应拉伸。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

需要均匀分布的按钮行 的相关文章

  • 如何增加 Gradle 守护进程的最大堆大小?

    签署 apk 时 我收到以下消息 To run dex in process the Gradle daemon needs a larger heap It currently has 1024 MB For faster builds
  • 在运行时绘制HSV圆

    我想在我的应用程序中有一个颜色选择器 如下所示 我尝试过逐像素填充位图 尝试使用画布drawArc 方法 这两种方式都不利于性能 有任何想法吗 它可能不完全是它应该的样子 与颜色 饱和度等有关 但是这是一些东西 http i1272 pho
  • 强制关闭导致HTTP实体可能不为空

    这里是发送数据 Http 的完整代码 asynctask private class MyAsyncTaskPupuk extends AsyncTask
  • 在 Android 上检测已接听的拨出电话

    我知道这个问题已经被问过很多次了 但没有答案 但我仍然希望有人终于解决了这个问题 问题 我有一台运行 Android 2 3 的未 root 设备 我需要创建一项服务 打电话 等待呼叫被应答 接听电话后挂断电话 有超时 和其他许多人一样 我
  • XAMARIN - 添加来自 youtube 的视频

    我搜索如何从 youtube 添加视频的信息 例如 我想从一些 YouTube 链接添加视频 我认为它应该在网络视图中 但我需要一些详细信息 因为我找不到有关我的问题的任何信息 您可以使用 webview 播放 youtube 视频 str
  • Android 服务 START_STICKY START_NOT_STICKY

    我需要让我的服务始终在后台运行 并使用 startService 函数启动我的服务 无论应用程序的状态如何 我都不想重新启动服务 这是我的观察 START STICKY gt 如果应用程序启动 则服务正在重新启动 当应用程序关闭时 服务也会
  • Android:让用户从图库中选择图像或视频

    是否可以以这样的方式启动图库 以便同时显示图片和视频 Thanks 从图库中选择音频文件 Use MediaStore Audio Media EXTERNAL CONTENT URI Intent intent new Intent In
  • Android物理引擎[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 在研究了 3D 游戏编程之后 很快就明白了为什么物理引擎非常有用 Android 支持哪些物理引擎并且可以在 Android 上使用 关于
  • 不同风格的模块文件

    我正在尝试在同一个应用程序中实现播放服务和华为服务 但希望能够按风格配置使用哪一个 每种风格都使用自己的 applicationIdSuffix 因此 对于每种不同的风格 华为插件都会失败 我无法编译 我的应用程序模块包含agconnect
  • 由带有换行符的 DOMDocument 生成的 XML

    我正在使用 PHP DOMDocument 创建 XML 文件 并且这些 XML 文件不能包含换行符 但是当我使用该方法时 保存 XML 生成的 XML 在定义和初始标记之间有一个换行符 如下所示
  • 单击“发送”按钮事件时,我们可以在哪里获取 xml/元数据格式的表单数据?

    我是一个新的 scala 学习者 作为要求的一部分 我需要将表单数据插入 activemq 队列中以进行提交事件 我尝试调试发送方法代码 以了解单击 FormRunnerActions scala 类中的发送按钮时我们到底在哪里获取 xml
  • 为什么 Android 上的免安装应用有两种设置?

    我使用的是运行 Android 11 的 Pixel 3 我发现有 2 种不同的设置可以控制免安装应用的某些方面 设置 应用程序和通知 默认应用程序 打开链接 即时应用程序 即使未安装 也打开应用程序中的链接 切换默认为开 Google P
  • 应用程序运行时相对布局中的元素显示不同

    我有一个ListView在片段内创建 并且它有一个搜索过滤器 问题是 XML 布局在 android studio 中显示正常 但在模拟器或手机中运行时 它显示不同 与我对齐时不正确 并且当我单击SearchView它位于选项卡导航下方 谁
  • 测试应用内结算:“发布者无法购买此商品”

    我的应用程序似乎已准备好在我的设备上进行应用内购买程序的 现实生活 测试 但是 我在 Play 商店中收到 发布商无法购买此商品 的错误消息 现在 我应该如何测试这个 我不想通过仅用于测试的虚拟帐户重新安装手机来丢失手机的配置 在开发者控制
  • 使用磁场计算旋转矩阵

    在获取旋转矩阵值时它包含public static boolean getRotationMatrix float R float I float gravity float geomagnetic 这里我如何计算float gravity
  • 尝试重新打开已关闭的对象:sqlitequery

    所以本质上我查询数据库两次 我不明白这个错误真正来自哪里 因为我没有在任何地方关闭数据库 返回错误的代码是这样运行的 我查了一下 刚刚看到一个像我这样的案例 BeaconHandler pullAllDB new BeaconHandler
  • 如何为部分 Android 活动创建通用代码?

    我的申请中有 14 项活动 这 9 个活动中包含自定义标题栏和选项卡窗格 所以在这里我需要在一个地方编写这个通用代码 而不是在每个包含自定义标题栏和选项卡窗格代码的活动中编写冗余代码 即布局及其活动特定代码 有哪些可能的方法可以做到这一点
  • Android:在surfaceview上实现admob

    我有一个使用 SurfaceView 的小游戏形式的活动 下面是代码片段 我很困惑如何在 SurfaceView 上实现 admob 请建议 public class DroidzActivity extends Activity priv
  • 在自定义对话框中设置文本视图

    我创建了一个自定义对话框 但无法将文本设置到 java 对话框布局中的文本视图中 并且我的程序崩溃了 我的错误是什么 public class Total CBC extends Activity Override protected vo
  • 带有包含布局的导航抽屉布局

    我认为我的问题实际上很简单 但我不知道如何解决 有一个工作导航抽屉 代码如下

随机推荐

  • 为什么我不能将变量传递到 PHP 中的包含文件中?

    我以前也遇到过这个问题before https stackoverflow com questions 1601348 passing php variables to an included file没有真正的解决方案 又出现这种情况了
  • 需要时自动加载函数/类库

    首先 介绍一下背景 我工作的公司使用massive函数 类库 它包含在每个页面上 成千上万行函数 其中 90 甚至可能不会在页面上调用 为了稍微减轻服务器负载 我一直在尝试更智能的库设置 为此 我将整个文件分成分类库文件 即 sql fun
  • rate() 函数如何平均请求持续时间?

    引自 普罗米修斯 观察值的计数和总和 https prometheus io docs practices histograms count and sum of observations doc 要根据名为 http request du
  • 浮动 div css 下的 margin-top

    我在 float right div 下有一个 div 由于某种原因 上边距无法应用于第一个 div 这是CSS over width 80 float right color e68200 under clear both backgro
  • WPF 中的数据模板

    我有一个关于 WPF 中的数据模板的一般性问题 假设我有一个名为 Question 的抽象类 以及各种子类 例如 MathQuestion GeographyQuestion 等 在某些情况下 使用 Question 数据模板将问题呈现为
  • 从作为引擎安装的 gem 重载 lib 文件

    我正在使用作为引擎安装的 gem 并想要自定义一些类 我想要重载的文件位于我的本地 rvm 目录中 rvmdir gem lib modulename containers file to override rb 我将文件复制到我的应用程序
  • 如何保证时间戳始终是唯一的?

    我使用时间戳对程序中的并发更改进行临时排序 并要求更改的每个时间戳都是唯一的 但是 我发现只需调用DateTime Now是不够的 因为如果快速连续调用它通常会返回相同的值 我有一些想法 但我认为没有什么是 最佳 解决方案 我是否可以编写一
  • MSBuild:包含自定义资源文件作为嵌入资源

    我在构建时使用 MSBuild 动态生成资源文件 但为了能够在运行时读取该资源文件 我需要它成为嵌入式资源 我到处都在研究如何在 a 中标记文件 csproj作为嵌入式资源 我什至尝试过这一点 但没有成功
  • json.net 特殊字符转义

    对 JSON 有点陌生 所以请原谅这个简单的问题 但根据找到的特殊字符列表here http www w3schools com js js special characters asp and here https developer m
  • Qt-fy 现有枚举与 Qt 元数据一起使用

    假设我有一个现有的enum X A B 并希望将其与 Qt 元数据一起使用 例如QMetaObject QMetaEnum QMetaObject meta FsxSimConnectQtfier staticMetaObject for
  • 高可靠性/可用性/安全性编码 - 我应该阅读哪些标准?

    我听说汽车行业有一个叫做 MISRA C 的东西 其他高可靠性 可用性 安全行业的相关标准是什么 比如 Space Aircraft 银行 金融 汽车 Medical 国防 军事 Adam 参观戈达德太空飞行中心及其编码标准 http so
  • 使用“mysql_fetch_row”从数据库检索结果并使用 PHP 和 mysqli 插入数组?

    我需要从几行检索数据 然后将结果插入到枚举数组中 这样我就可以使用 for 循环来回显它 我有这个 我已经连接到数据库 genres sql SELECT genreID FROM genres WHERE imdbID if stmt g
  • 如何基于Web服务更改android中的语言

    目前 我正在开发我正在使用的 Android 项目English作为主要语言 我在用着strings xml字符串常量文件 现在 我想根据网络服务动态更改语言 该服务将根据用户选择 在 设置 中 创建 我知道我们必须为每种语言创建单独的 s
  • 如何最好地设计具有多个过滤器的 REST API?

    作为一个个人编程项目 我正在抓取我大学的课程目录并以 REST API 的形式提供数据 我已成功抓取所有数据并将其存储在数据库中 现在正在开发 API 课程可以根据许多标准进行过滤 教师 学院 学分 时间 日期等 在这种情况下提供 API
  • 微风错误:非法构造 - 使用“或”组合检查

    我遇到了这个微风错误 非法构造 使用 或 来组合检查 在 Chrome 上加载实体的编辑页面时 当我刷新页面时 错误消息不再出现 此错误在我的网站上随机 不规则地发生 我无法使用指定的场景重现它 只是随机遇到它 我在 Breeze 代码中看
  • Nuxt中间件无限重定向问题

    您好 我正在尝试在我的 Nuxt 3 应用程序中执行这个中间件 我正在尝试遵循文档 但收到无限重定向错误 export default defineNuxtRouteMiddleware to from gt const user id 1
  • python TypeError:“列表”对象不可调用错误

    我是 python 新手 我试图理解这里的一个基本错误 我在下面的代码中收到 TypeError list object is not callable 错误 有人可以解释一下我的代码有什么问题吗 graph a b c b a c c b
  • 通过 AKS 群集中的负载均衡器访问服务

    我配置了一个集群 其中的服务 及其相关的 Pod 容器 全部部署到私有子网中 其中一个 Pod 代表应用程序的 UI 我定义了一个具有公共 IP 的负载均衡器来提供对 UI 的访问 至少这是我的意图 当我在浏览器中输入包含负载均衡器 IP
  • Angular Js+ TypeScript:如何创建动态表

    我是打字稿和角度的新手 我已经使用打字稿和角度js实现了一个模块 在其中我需要创建一个动态表 它将获取演示文稿的类型并相应地附加到我的视图 就像我之前在 C 中所做的那样 我在下面给出了我的 c 代码 private void ShowCu
  • 需要均匀分布的按钮行

    我尝试使用 3 行和 4 列将所有按钮水平均匀地隔开 但失败了 垂直的就好 下面是 3 种不同的按钮间隔尝试 我的 3 行每行 1 种 第一行拉伸图形 这是不需要的 第二行不拉伸但没有间距 图形之间需要间距 而第三行拉伸没有任何间距 请帮我