viewpager2与SwipeRefreshLayout的交互 [英] viewpager2 interaction with SwipeRefreshLayout
问题描述
我有4个片段的viewpager2.其中3个具有SwipeRefreshLayout来刷新特定片段中的异步任务数据.
I have viewpager2 with 4 fragments. 3 of them have SwipeRefreshLayout to refresh async task data in particular fragments.
使用SwipeRefreshLayout和viewpager2时,手势有些冲突.IE.向下滑动刷新以使屏幕如此敏感,向左或向右移动一点也可以使页面屏幕发生变化,刷新图标被冻结或过程未完成.
When using SwipeRefreshLayout and viewpager2 the gestures are somehow conflicting. ie. swype down to refresh makes screen so sensitive, that a little move to left or right also makes page screen change and refresh icon is freezing or the processis unfinished.
我的目标是使手势独立,例如,当我开始向下滑动SwipeRefreshLayout时,vp2被禁用,因此不会干扰SRL.
my goal is to make gestures independent, so for example when i start to swype down SwipeRefreshLayout, then vp2 is disabled so it it is not interfere with SRL.
在将标准viewpager与SwipeRefreshLayout一起使用时,这没有发生,手势没有冲突,但是我需要在VP2中使用"setUserInputEnabled".任何想法如何减轻这种行为,我应该在SwipeRefreshLayout级别还是在viepager2代码中减轻它?
This was not happening when using standard viewpager with SwipeRefreshLayout, gestures were not conflicting, but I need to use "setUserInputEnabled" in VP2. any idea how to mitigate this behaviour and should i mitigate it at SwipeRefreshLayout level or within viepager2 code?
推荐答案
当我添加到滚动视图时,问题似乎已解决:
It looks problem is resolved when I added to my scrollview:
android:nestedScrollingEnabled="true"
片段布局的最终代码如下:
Final code of the fragment layout then looks like this:
<?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" />
...
这篇关于viewpager2与SwipeRefreshLayout的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!