我有4个片段的viewpager2。其中3个具有用于刷新特定片段中的异步任务数据的SwipeRefreshLayout。
在使用SwipeRefreshLayout和viewpager2时,手势会发生某种程度的冲突。即。向下输入刷新会使屏幕变得非常敏感,以至于稍微向左或向右移动也会使页面屏幕发生变化,刷新图标冻结或进程未完成。
我的目标是让手势独立,例如,当我开始向下输入SwipeRefreshLayout时,vp2就会被禁用,这样它就不会干扰SRL。
在SwipeRefreshLayout中使用标准的viewpager时不会发生这种情况,手势不会冲突,但我需要在VP2中使用"setUserInputEnabled“。你知道如何缓解这种行为吗?我应该在SwipeRefreshLayout级别还是在viepager2代码中缓解它?
发布于 2019-08-04 00:21:17
当我添加到我的滚动视图时,问题看起来已经解决了:
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" />..。
发布于 2020-05-22 01:42:38
编辑__:更新为1.1.0已于2020年7月22日发布
该问题是由于SwipeRefreshLayout中的错误造成的,该错误已在版本1.1.0中得到解决。要使用它,只需通过在Gradle文件的依赖项中添加以下行来升级到该版本:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'有关错误历史记录,请参阅issueTracker:[ViewPager2] SwipeRefreshLayout should not ignore requestDisallowInterceptTouchEvent。请注意,这里还描述了一种解决方法(扩展SwipeRefreshLayout并覆盖"requestDisallowInterceptTouchEvent")。
发布于 2020-03-26 01:42:03
如果你在SwipeRefreshLayout中有RecyclerView,你需要在FrameLayout中包装RecyclerView,或者任何其他布局,并设置nestedScrollingEnabled="true" on layout not on 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>https://stackoverflow.com/questions/57336292
复制相似问题