Android LinearLayout 在 Horizo​​ntalScrollView 中具有多行

2023-12-13

我在 Horizo​​ntalScrollView 中使用 LinearLayout ,滚动部分正在工作,但我不知道如何制作 3 行。


例如:

Bold显示当前显示的内容(在模拟器中/在屏幕上)

Current

--按钮1--按钮2--按钮3--按钮4--按钮5--按钮6--按钮7--按钮8--按钮9--按钮10

-按钮11--按钮12

我想要的是

--按钮1--按钮2--按钮3--按钮4--按钮5--按钮6--
--按钮7--按钮8--按钮9--按钮10--按钮11--按钮12--


我正在尝试使用一个 LinearView 来完成此操作,因为稍后我将尝试动态添加按钮。

我可能以完全错误的方式这样做(我认为我是)。

这是代码:

 <HorizontalScrollView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginTop="50dp" >

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

            <Button
            android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button1" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button2" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button3" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button4" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button5" />
             <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button6" />
             <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button7" />
             <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button8" />
              <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button9" />
               <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button10" />
                <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button11" />
                 <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button12" />

        </LinearLayout>
    </HorizontalScrollView>

我尝试了一些事情,但我总是回到起点。


而不是 LinearLayout 尝试网格布局这是 Android 支持库的一部分。

它可以在 XML 布局中实现时设置列数和行数。

像下面这样的东西

 <HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp" >

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="6"
        android:rowCount="3"
        android:orientation="horizontal" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button3" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button4" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button5" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button6" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button7" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button8" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button9" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button10" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button11" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button12" />
    </GridLayout>
 </HorizontalScrollView>

Edit -如果您想添加不同宽度的子视图,可以使用 TableLayout 而不是 GridLayout,如下所示

  <HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button1" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button2" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button3" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button4" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button5" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button6" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button7" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button8" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button9" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button10" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button11" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button12" />
        </TableRow>
    </TableLayout>
</HorizontalScrollView>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android LinearLayout 在 Horizo​​ntalScrollView 中具有多行 的相关文章

随机推荐

  • 将姓氏、名字切换为列表中的姓氏

    我有两份体育运动员名单 一种结构简单 Lastname Firstname Lastname2 Firstname2 第二个是结构列表的列表 Firstname Lastname Team Position Ranking 我最终想搜索第二
  • 如何解决 ORA-02014:无法从具有 DISTINCT、GROUP BY 等的视图中选择 FOR UPDATE

    我想锁定表中的一条记录 该记录被指定为 ID 大于 的下一个 CREATE TABLE test id number SELECT id FROM SELECT id FROM test WHERE id gt 10 ORDER BY id
  • 用于检测旧版 Internet Explorer 并提供下载较新浏览器的 JavaScript

    我正在寻找一些好看的东西 我可以将其粘贴到页面上并完成它 该脚本应该检测早于 9 的 IE 版本 并显示一个漂亮的弹出窗口 其中包含指向不同浏览器的链接或类似内容 我可以自己做 但我不想重新发明轮子 当我第一次发布这个答案时 现代IE项目正
  • 在 Windows Vista 上覆盖 C:\Program\MyProg 中的可执行文件

    我希望我的程序能够自我更新 从 ftp 下载新的 exe 和 或其他一些文件 并且我使用了已接受答案中的配方这个问题 Recap 将运行程序重命名为old mp exe 直接下载更新为 mp exe 重新启动程序 这对于 Windows X
  • 将数字四舍五入到小数点后第一位

    我想知道可用的手机内存 所以我写了这段代码 File path2 Environment getDataDirectory StatFs stat2 new StatFs path getPath long blockSize2 stat
  • APNS(Apple 推送通知服务)可靠性

    我们的应用程序使用 APNS 接收推送通知 然而 我们的客户声称他们的一些设备没有收到通知 并辩称他们 必须 确保 100 发送通知 但我读过某处APNS 并非 100 可靠 应该存在通知未发送的情况 我目前对如何确保随时收到 APNS 感
  • 如何使用分散发送数组的一部分?

    我正在自学 Python mpi4py 模块 用于在多个进程中进行编程 我编写了以下代码来练习分散 from mpi4py import MPI comm MPI COMM WORLD size comm Get size rank com
  • 如何将 Flask 响应对象转换为字典

    我知道flask jsonify返回一个flask Response对象 但是我不知道如何将此对象转换为字典 我该怎么做呢 app route methods GET def hello Accept and jsonify GET req
  • 通过 ASP.NET 应用程序启用 process.start 需要哪些权限?

    我有一个 asp net 应用程序 它使用 process start 来调用可执行文件 Graphviz 一切在我的开发环境中运行良好 但是当我转向生产时 我无法运行该流程 详细信息如下 我创建了这个简单的子来展示这个问题 Protect
  • 如何在 Flutter 中拉伸图像以适合整个背景(100% 高度 x 100% 宽度)?

    我的图像与我的设备屏幕的宽高比不匹配 我想拉伸图像以使其完全填满屏幕 并且我不想裁剪图像的任何部分 CSS有百分比的概念 所以我可以将高度和宽度设置为100 但 Flutter 似乎没有这个概念 而且仅仅硬编码高度和宽度是不好的 所以我被困
  • 获取字符串中的中间/开始/结束阿拉伯字符

    大多数阿拉伯字母都有多种上下文形式 例如后者 有通用unicode0628 但如果后者出现在单词的开头将采用这种形式 统一码FE91 中 统一码FE92 词尾 统一码FE90 我正在尝试获取 char 代码 但我总是得到通用的 unicod
  • 如果购物车中有特定产品,请禁用所有支付网关

    我想在特殊情况下禁用所有支付网关 我有 2 种特殊产品 我不想在结账时与任何其他产品组合使用 可以说我的 特别的 产品 ID 是496 and 484 所有其他都是 normal 产品 如果其中之一 特别的 产品在购物车中 例如我想禁用 p
  • Rails 实现自动完成搜索

    我不确定如何为我的搜索功能添加自动完成表单 我有一个具有自定义操作的以下控制器 def query users Search user params query article Search article params query end
  • SQL Server 2005 用 0 填充数据透视表

    I have 这个查询在 SQL Server 2005 中 我仅使用更方便的 2008 插入方法作为示例 我需要在网格输出中将 null 替换为 0 无论如何要这样做吗 你会使用ISNULL 功能 看SQL小提琴 SELECT lesso
  • 在开发过程中调整 MySQL 以快速创建列/索引

    假设 MySQL MyISAM 表包含 1 GB 数据和 1 GB 索引 此外 假设在开发过程中 列和索引将非常频繁地从表中添加和删除 由于数据库的大小 使用标准的未调整的 MySQL 设置时 列 索引的创建速度很慢 为了最大限度地减少添加
  • 获取传递给方法的参数名称[重复]

    这个问题在这里已经有答案了 复制 确定用作方法参数的变量名称 有什么方法可以检索传递给方法的参数的名称 例如 int someParameter 1 Method someParameter public void Method int p
  • NextJS React - WebpackError:窗口未定义

    我正在尝试玩 React 我遵循了 NextJs 的 入门 教程 link 并且我已经成功创建了新项目 一旦我尝试导入第三方插件 例如当前设备 or 平滑滚动条我收到以下错误 ReferenceError window is not def
  • .Net Maui:如何从任何内容页面(MVVM)读取/写入(获取/设置)全局对象

    我确信我在这里遗漏了一些深刻或明显的概念 现在我有了一个页面 可以设置各种蓝牙传感器并从心率监视器 速度计和踏频传感器获取数据 使用插件 BLE 因此 我在 ViewModel 中为名为 BluetoothPage 的 ContentPag
  • 反转 CSS 动画

    我这样做了 http codepen io yayoni pen pgXoWY 当我点击小按钮时 我想反转动画 但我所做的不起作用 我不明白为什么 function anim var div document getElementById
  • Android LinearLayout 在 Horizo​​ntalScrollView 中具有多行

    我在 Horizo ntalScrollView 中使用 LinearLayout 滚动部分正在工作 但我不知道如何制作 3 行 例如 Bold显示当前显示的内容 在模拟器中 在屏幕上 Current 按钮1 按钮2 按钮3 按钮4 按钮5