当前位置: 首页 > 知识库问答 >
问题:

ViewPageer2与SwipeReFresLayout的交互

季小云
2023-03-14

我有4个片段的viewpager2。其中3个具有SwipeRefreshLayout以刷新特定片段中的异步任务数据。

当使用SwipeRefreshLayout和viewpager2时,手势在某种程度上是相互冲突的。例如,swype down to refresh(向下键入以刷新)使屏幕非常敏感,向左或向右移动一点也会使页面屏幕发生变化,刷新图标冻结或进程未完成。

我的目标是使手势独立,例如,当我开始向下键入SwipeRefreshLayout时,vp2被禁用,因此它不会干扰SRL。

在SwipeRefreshLayout中使用标准viewpager时不会发生这种情况,手势没有冲突,但我需要在VP2中使用“SetUserInputened”。知道如何缓解这种行为吗?我应该在SwipeRefreshLayout级别或在viepager2代码中缓解吗?

共有3个答案

叶经略
2023-03-14

如果您在SwipeRefreshLayout中有RecyclerView,则需要在FrameLayout中包装RecyclerView,并在layout上设置nestedScrollingEnabled=“true”,而不是在RecyclerView上设置。

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="true">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/media_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </FrameLayout>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
邵飞白
2023-03-14

添加到scrollview后,问题似乎得到了解决:

android:nestedScrollingEnabled="true"

片段布局的最终代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/some_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/activity_background"
tools:context="some_fragment_name">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:nestedScrollingEnabled="true" <<<<------ HERE the change
    android:id="@+id/some_id">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/sensors_relative_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="some_package_name">

    <TextView
        android:id="@+id/some_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="@android:color/white"
        android:gravity="center"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:layout_marginTop="5sp"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        android:textSize="20sp" />

。。。

弘烨烁
2023-03-14

编辑:更新为1.1.0已于2020年7月22日发布

该问题是由于SwipeRefreshLayout中的一个bug造成的,该bug已由版本1.1.0解决。要使用它,只需在Gradle文件的依赖项中添加以下行即可升级到该版本:

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

有关错误历史记录,请参阅问题跟踪器:[ViewPager2]SwipeReFresLayout不应忽略Request estDislowInterceptTouchEvent。请注意,那里还描述了一个解决方法(扩展SwipeReFresLayout并覆盖“Request estDislowInterceptTouchEvent”)。

 类似资料:
  • 问题内容: 我一直在研究Python的模块,我想使用python的bash进行“交互式会话”。我希望能够像在终端模拟器上一样从Python读取bash输出/写入命令。我猜一个代码示例可以更好地解释它: (显然,这种方式行不通。)是否可能出现这种情况,怎么办? 非常感谢 问题答案: 请尝试以下示例: 您必须阅读有关stdin,stdout和stderr的更多信息。看起来不错的演讲:http://ww

  • JavaScript 调用 Krpano 对象 embedpano({ //省略其它不相关设置... id: "krpanoSWFObject", onready: krpanoReady }); function krpanoReady() { var krpano = document.getElementById('krpanoSWFObject');

  • 交换机与控制器交互 我们可以启动一个简单的控制器,默认没有任何流表项,仅仅作为一台带学习功能的交换机。控制器默认监听端口是 6633。 以下控制器与交换机之间的消息交互过程,可以通过 wireshark,配置 of 过滤器观察到交换机跟控制器之间的交互消息。 参见下面的表格。 消息 类型 描述 Hello Controller->Switch 跟着 TCP 握手,控制器发送它的版本号到交换机。 H

  • 这个剧本 }); 正在引起通信路由的错误 /updatechat 但是如果在前一段代码中,我替换为 这个"var=request.form['var']"表单在我的代码中的几个不同的路由上工作

  • 我想在事务中使用SpringKafka,但我真的不明白应该如何配置它以及它是如何工作的。 这是我的配置 此配置用于事务id前缀为的DefaultKafkaProducerFactory: 问题一: 我应该如何选择这个交易ID前缀?如果我理解正确,这个前缀被Spring用来为创建的每个生产者生成一个事务性id。 为什么我们不能只使用"UUID。随机UUID()? 问题二: 如果生产者被销毁,它将生成

  • C语言外部函数接口 CFFI 提供了一套简单易用的机制来帮助 CPython 和 PyPy 与 C 语言进行交互。它支持两种模式:一种是内联的 ABI 兼容模式(下面举例说明),这一模式允许您从可执行模块中动态加载和运行函数(本质上与 LoadLibrary 和 dlopen 的功能相同);另一种是 API 模式,这一模式允许您构建 C 语言扩展模块。 from cffi import FFI f