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 中具有多行 的相关文章

  • Android Paint:如何获得“喷枪”效果?

    我正在关注 API 演示中的 FingerPaint 演示 我需要获得 喷枪 效果 从某种意义上说 当我在同一个点上绘制时 它会变得越来越暗 请看图片 正如你所看到的 中心更暗 因为我不止一次在同一个地方涂上油漆 请问 如果绘制多次 如何获
  • Android:处理电话中的语音

    我目前正在寻找有关如何在 Android 上操作音频的选项 目标是在通话期间实时处理来自麦克风的音频 最好的解决方案是在本机调用中执行此操作 但重建一个电话应用程序 无 VOIP 也可以 有没有什么方法可以使用 Android API 来实
  • 有没有办法有一个屏蔽数字输入字段?

    我正在 Android 上创建一个 HTML5 应用程序 对于这个特定场景 我们有一个用于信用卡安全代码的输入字段 我们希望强制输入字段仅包含数字并被屏蔽 我没有运气搜索这个特定的案例 从我自己研究 尝试中可以看出 这不能纯粹通过 HTML
  • Android 自定义对话框因布局而膨胀 - 对齐问题

    我有一个自定义对话框 它是从dialog xml 中膨胀的 当我打开对话框时 它看起来如下所示 我在列表视图和它下面的 确定 按钮之间有一些空间 我想消除列表视图与其下方的按钮之间的空间 我怎样才能做到这一点 对话框 xml
  • 当用户将 Android 11 应用程序置于后台时,除非手机已连接电源,否则我的 Android 11 应用程序将停止运行

    我编写了一个前台服务 以确保我的应用程序在进入后台时可以继续运行 该应用程序需要在后台运行 因为在计时器到期后 它会发出声音并振动以提醒用户 但是 当按下电源或主页按钮时 应用程序的计时器将在大约 15 分钟后停止运行 除非手机已插入电源
  • 加载内容时在 ImageView 中使用“动画圆圈”

    我目前在我的应用程序中使用一个列表视图 可能需要一秒钟才能显示 我目前所做的是使用列表视图的 id android empty 属性来创建 正在加载 文本
  • 如何将 ThreeJS 与 PhoneGap 一起使用?

    这个探索是非常自我描述的 我已经用一个简单的 3D 立方体进行了测试 它在浏览器中运行良好 但只在模拟器中显示空白页面 有人说 Threejs 不能与 PhoneGap 一起使用 但也有人说他们使用过并且工作正常 在 Android 中 您
  • Android HTTP-post AsyncHttpClient

    public void postLoginData AsyncHttpClient myClient new AsyncHttpClient RequestParams params1 new RequestParams params1 p
  • 为什么 Cursor.requery() 被标记为“已弃用”?

    Cursor requery 是一种非常常见的方法 使用它来刷新 ListView 的内容 但为什么这个方法被标记为 已弃用 呢 我不太清楚 API 文档上的原因 Cursor requery API http developer andr
  • Android - 如何在 ListView 的背景上显示垂直线(并根据行高)?

    如何在背景上显示一条垂直线 如下图蓝色突出显示的那条 在此示例中 我有一个带有 ImageView 元素的 ListView 和 TextView 但它与线条无关 并且我希望这些项目的背景上有一条垂直线 让人感觉它们与每个项目 连接 另请注
  • 如何在 Android 应用程序中使用 xmlserializer 创建 xml

    您好 我正在制作一个预订应用程序 我需要在创建 xml 后将 xml 发送到服务器 如何使用创建 xmlxmlserializer创建后将其发送到服务器 http api ean com ean services rs hotel v3 l
  • 如何计算android中位图擦除区域的百分比?

    我是安卓新手 我正在制作一个可以使用手指擦除画布上的位图的应用程序 像手指画橡皮擦之类的东西 我想计算擦除区域的百分比 例如 60 已从完整图像中擦除 请帮助我做到这一点 提前致谢 我尝试了一些方法 它总是给我 0 它不起作用 请参阅该方法
  • 像 Google Play 商店一样在垂直 RecyclerView 中动态不同图像水平 RecyclerView

    我一直在关注这个教程 http android pratap blogspot co za 2015 12 horizo ntal recyclerview in vertical html http android pratap blog
  • ViewPagerIndicator:TabPagerIndicator 不可见

    我现在正在为 viewpageinderdicator 苦苦挣扎 当我使用 TitlePageIndicator 时 一切正常 但是当我尝试使用 TabPageIndicator 时我看不到它 它不会出现在层次结构视图中 我尝试了很多东西
  • Android 对 Runtime.getRuntime().exec() 的权限

    我有一个应用程序在清单上具有以下权限 我的应用程序在 Android JB 4 1 2 上运行 UPDATE 我尝试在 JB 上运行该应用程序 但它不起作用 它适用于早期的 API 版本
  • Android jUnit 测试 java.lang.NoClassDefFoundError: android/database/sqlite/SQLiteOpenHelper

    我正在尝试运行一个模拟子类的单元测试SQLiteOpenHelper但我收到以下错误 java lang NoClassDefFoundError android database sqlite SQLiteOpenHelper at ja
  • 安卓浮动键盘

    是否可以通过编程方式更改键盘的位置 我正在开发一个图腾应用程序 如果键盘停靠在底部 则很难使用 我尝试创建一个扩展 InputMethodService 的自定义键盘 并且我能够更改按键的布局 但我无法更改键盘的视图位置 快捷键 https
  • 屏幕方向更改后应用程序崩溃

    我有以下问题 启动后 应用程序工作正常 即使在更改屏幕方向后也是如此 应用程序尚未准备好处理方向更改 例如替代布局等 因此仅显示旋转的默认布局就可以了 但是 当我通过按后退键离开应用程序 更改方向并在再次启动应用程序后立即崩溃 崩溃后 如果
  • SubscriptionManager 用于读取运行 Android 5.1+ 的双 SIM 设备的 IMSI

    对于 API 22 我尝试使用 SubscriptionManager 读取双 SIM 卡 IMSI IMSI 是 14 到 15 个字符 格式如下 MCC MNC MSIN MCC 移动国家 地区代码 例如 美国为 310 MNC 移动网
  • Android:防止嗅探(例如使用 CharlesProxy)SSL 流量

    我使用 Charles 检查将我的应用程序发送到 HTTPS 的数据 我在手机上安装了 Charles CA 证书 因此我能够解密每个 SSL 流量 但我发现一些应用程序无法看到 SSL 流量 我如何将这种行为实现到我自己的应用程序中 有了

随机推荐

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

    我有两份体育运动员名单 一种结构简单 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