ScrollView 中的 ListView 在 Android 上不滚动

2024-02-19

我在滚动时遇到问题ListView里面一个ScrollView。我有一个 Activity,顶部有一些 EditText,然后是一个带有两个选项卡的选项卡主机,每个选项卡都有一个 ListView。当 EditText 视图聚焦时,软键盘会出现,并且由于我有 ScrollView,内容是可滚动的。但是当 ListViews 中有更多项目(选项卡中的项目)时,问题就出现了,即使有更多项目,我也无法滚动 ListView。

以下是布局 XML:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="?backgroundImage"
    android:orientation="vertical">

  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dip"
        android:id="@+id/buttons">
    <Button
            android:text="Save"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnSaveorUpdate"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
    <Button
            android:text="Cancel"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnCancelorDelete"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
  </LinearLayout>
  <ScrollView
        android:layout_above="@id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_margin="10dip">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dip">
      <TextView
                android:text="Bill details"
                android:textColor="?textColorDark"
                android:layout_alignParentTop="true"
                android:id="@+id/txtEnterDetails"
                android:textSize="25dip"
                android:textStyle="bold"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_marginBottom="2dip"></TextView>
      <LinearLayout
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_width="0dip"
                android:layout_height="0dip" />
      <EditText
                android:layout_width="fill_parent"
                android:hint="Enter data"
                android:inputType="numberDecimal"
                android:id="@+id/txtSample"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtDescription"
                android:hint="Enter description"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:inputType="text"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtComment"
                android:hint="Enter comment (if any)"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:inputType="text"
                android:text=""></EditText>
      <LinearLayout
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
        <TextView
                    android:id="@+id/txtDate"
                    android:layout_width="wrap_content"
                    android:text=""
                    android:textSize="20dip"
                    android:textColor="?textColorDark"
                    android:layout_marginLeft="10dip"
                    android:layout_height="@dimen/editTextHeight"
                    android:layout_gravity="center_vertical" />
        <Button
                    android:id="@+id/btnPickDate"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/editTextHeight"
                    android:text="Select date"
                    android:layout_margin="2dip"
                    android:textSize="15dip"
                    android:layout_gravity="center_vertical" />
      </LinearLayout>
      <TabHost
                android:id="@+id/tabhost"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
        <LinearLayout
                    android:id="@+id/linearLayout1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical">
          <TabWidget
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:id="@android:id/tabs"></TabWidget>
          <FrameLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:id="@android:id/tabcontent">
            <ScrollView
                            android:layout_above="@id/buttons"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:fillViewport="true"
                            android:id="@+id/tab1">
              <LinearLayout
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical">
                <TableLayout
                                    android:layout_height="wrap_content"
                                    android:layout_width="fill_parent">
                  <TableRow
                                        android:id="@+id/tableRow1"
                                        android:layout_marginLeft="2dip"
                                        android:layout_marginRight="5dip"
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content">
                    <LinearLayout
                                            android:layout_width="fill_parent"
                                            android:layout_height="wrap_content"
                                            android:orientation="horizontal">
                      <ImageView
                                                android:src="@drawable/ic_menu_invite"
                                                android:layout_width="40dip"
                                                android:layout_height="40dip"
                                                android:layout_gravity="center_vertical"></ImageView>
                      <TextView
                                                android:text="Add friend"
                                                android:layout_height="wrap_content"
                                                android:layout_width="fill_parent"
                                                android:layout_centerVertical="true"
                                                android:textColor="?textColorDark"
                                                android:textSize="@dimen/editText"
                                                android:layout_gravity="center_vertical" />
                    </LinearLayout>
                  </TableRow>
                  <TableRow
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:layout_marginLeft="5dip"
                                        android:layout_marginRight="5dip">
                    <TextView
                                            android:id="@+id/txtData1"
                                            android:layout_width="170dip"
                                            android:layout_height="wrap_content"
                                            android:text="Data"
                                            android:textSize="14dip"
                                            android:textStyle="bold"
                                            android:textColor="#000000">
                    </TextView>
                    <TextView
                                            android:id="@+id/txtData2"
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:text="Sample"
                                            android:textSize="13dip"
                                            android:textColor="#000000"></TextView>

                  </TableRow>
                </TableLayout>
                <ListView
                                    android:cacheColorHint="#00000000"
                                    android:id="@+id/ListView01"
                                    android:layout_height="wrap_content"
                                    android:layout_width="fill_parent" />
              </LinearLayout>
            </ScrollView>
            <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center_horizontal"
                            android:id="@+id/tab2"
                            android:orientation="vertical">
              <TableLayout
                                android:layout_height="wrap_content"
                                android:layout_width="fill_parent">
                <TableRow
                                    android:id="@+id/tableRow2"
                                    android:layout_marginLeft="2dip"
                                    android:layout_marginRight="5dip"
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content">
                  <LinearLayout
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:orientation="horizontal">
                    <ImageView
                                            android:src="@drawable/ic_menu_invite"
                                            android:layout_width="40dip"
                                            android:layout_height="40dip"
                                            android:layout_gravity="center_vertical"></ImageView>
                    <TextView
                                            android:text="Sample"
                                            android:layout_height="wrap_content"
                                            android:layout_width="fill_parent"
                                            android:layout_centerVertical="true"
                                            android:textColor="?textColorDark"
                                            android:textSize="@dimen/editText"
                                            android:layout_gravity="center_vertical" />
                  </LinearLayout>
                </TableRow>
                <TableRow
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="5dip"
                                    android:layout_marginRight="5dip">
                  <TextView
                                        android:id="@+id/txtUser1"
                                        android:layout_width="170dip"
                                        android:layout_height="wrap_content"
                                        android:text="User"
                                        android:textSize="14dip"
                                        android:textStyle="bold"
                                        android:textColor="#000000">
                  </TextView>
                  <TextView
                                        android:id="@+id/txtUserData"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="UserData"
                                        android:textSize="13dip"
                                        android:textColor="#000000"></TextView>
                </TableRow>
              </TableLayout>

              <ListView
                                android:cacheColorHint="#00000000"
                                android:id="@+id/ListView02"
                                android:layout_height="wrap_content"
                                android:layout_width="fill_parent" />

            </LinearLayout>


          </FrameLayout>
        </LinearLayout>
      </TabHost>
    </LinearLayout>
  </ScrollView>
</RelativeLayout>

请问谁能告诉我这里有什么问题吗?我有另一篇关于 ScrollView 内的 ListView 问题的文章,但它们对我的情况没有用。


在 Stack Overflow 的答案中ScrollView 中的 MapView? https://stackoverflow.com/questions/6546108/mapview-inside-a-scrollview/6883831#6883831,我找到了一个效果很好并且可以滚动的解决方案ListView没有什么问题:

ListView lv = (ListView)findViewById(R.id.myListView);  // your
listview inside scrollview lv.setOnTouchListener(new
ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
          int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

这样做的作用是禁用TouchEvent是在ScrollView并使ListView拦截他们。它很简单并且始终有效。

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

ScrollView 中的 ListView 在 Android 上不滚动 的相关文章

  • 随着手指的滑动改变活动

    我想知道如何通过滑动手指来更改活动 或者从右向左滑动手指并更改活动 就像我们在智能手机上看到图片的方式一样 有人知道吗 Cumpz 请参阅以下链接 http savagelook com blog android swipes or fli
  • 如何设计Android建筑物室内地图? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我想设计一个 Android 应用程序 它可以帮助学生和其他人在特定建筑物 一层 中导航 显示前往教室的步行方向 我需要帮助 这是您通
  • Android Volley:意外响应代码 405

    我的 Android Volley JsonObjectRequest 遇到 onErrorResponse 并出现以下问题 BasicNetwork performRequest Unexpected response code 405
  • 将 React Native 应用程序嵌入到现有的 ios/android 应用程序中

    我需要知道是否可以在现有的 ios android 应用程序中 嵌入 一个 React Native 应用程序 而不共享 React Native 应用程序代码 我们目前有一个 React Native 应用程序 它使用一些插件依赖项 并被
  • 为什么Android room不建议使用allowMainThreadQueries()?

    我正在创建一个小型应用程序 仅在数据库中保存一些计数器 如果不存在 请插入一个 如果是的话 增加更新 该应用程序没有任何用户界面 它是一个保存和读取数据 少量表 少量记录 的插件 我可以用吗允许主线程查询 在这种情况下 每次我读到一些关于这
  • 从txt文件中读取数据而不下载它?

    我想从提供的文本文件中解析信息 有没有一种方法可以在应用程序中执行此操作 而无需先下载文件 以某种方式传输文本内容 打开到 URL 的 Http 连接 使用内置 HttpURLConnection 或使用 commons httpclien
  • 从 Android 函数更新 Textview

    有人可以告诉我如何从函数更新 Android Textview 控件吗 我在互联网上进行了深入搜索 看到很多人都问同样的问题 我测试了线程但无法工作 有人有一个简单的工作示例吗 例如 调用一个函数 在循环中运行多次 并且该函数在 TextV
  • MyGestureDetector 扩展了 SimpleOnGestureListener

    我正在实现一个扩展 SimpleOnGestureListener 的 MyGestureDetector 我从以下机构借了课程 http www codeshogun com blog tag view flipper http www
  • Android Studio 与 Google Play 服务的编译问题

    我正在运行 Android Studio 0 8 4 并在 Android Studio 0 8 2 上尝试过此操作 我正在运行 Java JDK 1 8 0 11 并尝试使用 JDK 1 8 0 05 每当我尝试构建我的 android
  • Android 中的处理程序到处理程序与 Messenger 到 Messenger 通信

    问题 使用起来是否 更好 更快且开销更少 Handler http developer android com reference android os Handler html与使用 Handler 通信相比信使 http develop
  • 彩信数据总是错误

    我正在从 Galaxy S6 读取短信和彩信数据 所有 SMS 消息都有一个date像这样的字段1456252633000 该数字是 unix 时间戳 1000 我发送 未收到 的彩信具有如下日期字段 1440628863时间戳是正确的 u
  • 定时器时间不作为变量改变?

    这是我的代码 private int V Time 1 try final Timer V Timer final Handler V Handler V Timer new Timer V Handler new Handler Loop
  • Horizo​​ntalScrollView 将 GridView 缩小为小行

    当我将 Horizo ntalScrollView 放在 GridView 周围时 GridView 会被压缩到左侧的一个小列中 Gridview 的垂直滚动条甚至出现在左侧 Horizo ntalScrollView 的宽度设置为 fil
  • android gradle插件-离线安装

    我必须在离线电脑上安装 android gradle 插件 通过谷歌搜索 我了解到我可以通过本地 Maven 存储库来做到这一点 但从不成功的尝试和所有关于这个问题的质量保证中我知道这并不简单 我从来没有和maven一起工作过 有经验的人可
  • java.exe 以非零退出值 1 结束

    只是为了开始 我并不是真正尝试从 Android 中的 xlsx 文件中读取单元格 我已经尝试了几乎所有我在 Google 上搜索到的内容 但是每次 在两台不同的 PC 上 都是 Java 1 7 0 79 当我尝试构建 运行 这个应用程序
  • 什么是版本代码主要?和versionCode有什么区别?

    我刚刚发现PackageInfo versionCode https developer android com reference android content pm PackageInfo html versionCode在 Andr
  • 谷歌地图URL中参数的含义是什么

    我正在 Android 上使用 Webkit 浏览器 我想在以下 URL 中获得一个红色 A 符号
  • 如何将 Android 应用程序添加到已在 iOS 应用程序中使用的现有 Firebase 项目?

    我一直在我的 iOS 应用程序中使用 Firebase 项目 我现在想开始为 Android 应用程序使用相同的 Firebase 项目及其所有数据库和存储 在您的应用程序下Overview菜单 你应该按添加另一个应用程序并选择Androi
  • 如何检查设备上是否安装了电子邮件客户端

    我需要检查设备上是否安装了电子邮件客户端 我使用了以下代码 但它对我不起作用 public boolean isIntentAvailable final PackageManager packageManager getApplicati
  • Android:通过查找带有标签而不是 ID 的容器来添加片段

    我正在使用 for 循环创建片段的多个实例 在每个片段中 我需要添加另一组子片段 为此 我需要找到正确的容器 如果我使用容器的 ID 所有子片段都会添加到第一个父片段 而不是它们自己的父片段 在我的主要片段中 for ParentFragm

随机推荐

  • 使用 nginx 缓存 POST 响应:我应该将 Cache-Control 标头转发到客户端吗?

    我们的系统使用 POST 请求来预加载资产列表 给定相同的资产标识符列表 服务器将使用相同的资产数据列表进行响应 由于标识符列表可能非常长 它实际上是包含 JSON 列表的多部分请求 因此我们使用 POST 而不是 GET 尽管它is幂等的
  • 使用 pygame 通过按键结束循环

    我在 Ubuntu 上使用 PyGame 我想创建一个 while 循环 当用户按下键盘上的任何按钮时结束 这段代码不会离开循环 Eclipse 不会给出任何错误和警告 但永远不会离开循环 怎么了 import time import py
  • 具有不同参数的特征的 new() 方法

    我正在尝试使用具有不同内部参数的各种实现来创建一个特征 pub trait ERP fn new gt Self fn sample self gt f64 pub struct Bernoulli p f64 impl ERP for B
  • 如何编写Activerecord/Arel交集查询

    我在 PSQL 中得到了这个工作 SELECT profiles id FROM profiles INNER JOIN integration profiles ON integration profiles profile id pro
  • sim800 在指挥所数据到服务器

    我对向远程服务器发送数据感到困惑 我能够发送发布请求 但不确定如何添加服务器随后接收的数据 我已经浏览了数据表http www jarzebski pl datasheets SIM900 https 121018 1 00 pdf htt
  • MySQL 中空连接上的 group_concat

    我有以下问题 我有两个表 简化 User Role ID
  • 如何设置底部导航的高度

    所以由support V25 我们有一个名为底部导航的新组件 遵循设计指南 底部导航elevation应该8dp https material io guidelines components bottom navigation html
  • 使用 ymm 寄存器作为“类似内存”的存储位置

    考虑 x86 中的以下循环 on entry rdi has the number of iterations top some magic happens here to calculate a result in rax mov arr
  • 为什么我在 BBEdit 中的搜索导致“堆栈溢出”错误?

    我对 堆栈溢出 错误感到困惑 堆栈空间不足 应用程序错误代码 12246 当我执行 全部替换 时 我进入 BBEdit 搜索 article eprint article book r pmid eprint article book r
  • 限定 BigQuery 标准 SQL 中的等效子句

    BigQuery Standard SQ 中是否有 Teradata 的等效 Qualify 子句 我需要它 因为我们不能在Where Having 子句中使用分析函数 它已经发布了 在撰写本文时是 pre GA 现在是 GA 正如下面 R
  • 如何在将应用程序语言更改为阿拉伯语时显示阿拉伯语键盘?

    我有一个支持阿拉伯语和英语的移动应用程序 因此 为此 我使用两个单独的故事板在更改语言的同时从右向左翻转布局 不确定为阿拉伯语和马拉雅拉姆语使用两个单独的故事板是否是一个好主意 请建议任何其他更好的解决方案 但事实并非如此 我希望向用户展示
  • MYSQL、PHP插入数据库中的多个表

    我正在尝试将信息插入数据库中的多个表中 我已设法使用以下方法使其正常工作 query INSERT INTO users grp email college id tutor year password register date VALU
  • 将数据帧拆分为固定大小的行

    我有一堆长度不同的数据帧 范围从大约到 15 000 至 500 000 对于每个数据帧 我想将它们分成更小的数据帧 每个数据帧有 300 行 我将对其进行进一步处理 我怎样才能做到这一点 This 按行数拆分数据框 https stack
  • 解析和 Facebook SDK“Bolts”框架错误

    我有一个安装了 Parse 和 Facebook 框架的应用程序 Parse 是通过将文件拖动到项目的 Frameworks 文件夹并选择 如果需要则复制 来安装的 而 Facebook SDK 则是通过拖动而不选择复制选项来安装的 两者都
  • C# 将 Lambda 表达式作为方法参数传递

    我有一个 lambda 表达式 我希望能够传递和重用它 这是代码 public List
  • ms-access 本地化和默认布尔值

    我们的访问客户端即时生成 SQL 插入 更新和删除指令 并在 MS SQL Server 上发送 大多数用户拥有 Access 2007 的运行时版本 少数用户使用完整的 MS Access 版本 2003 或 2007 今天早上 我们国外
  • 鉴于我陷入了 SLF4J 和 java.util.Logging 的困境,最佳解决方案是什么?

    情况 我们使用带有异步附加程序的 SLF4j 和 Log4j 2 问题是我们还使用 JSF 它使用java util Logging 我看到各种关于使用性能的令人发指的警告jul to slf4j因为你不能就这么放弃java util Lo
  • 如何在VB.NET中实现地图功能

    我正在尝试实施Map在 VB NET 中 具有所描述的功能在这个答案中 https stackoverflow com questions 749084 jquery map vs each 应该需要一个IEnumerable Of TIn
  • 从 aws cp 中排除目录

    Mac 计算机上的当前项目目录包含一些文件和目录 需要复制到 aws s3 存储桶 但没有一些目录 其中一些目录是隐藏的 我无法弄清楚the docs http docs aws amazon com cli latest referenc
  • ScrollView 中的 ListView 在 Android 上不滚动

    我在滚动时遇到问题ListView里面一个ScrollView 我有一个 Activity 顶部有一些 EditText 然后是一个带有两个选项卡的选项卡主机 每个选项卡都有一个 ListView 当 EditText 视图聚焦时 软键盘会