当RecyclerView拖起时,我使用MotionLayout来实现一些很酷的效果,但是当我想在RecyclerView中使用SwipeRefreshLayout时,事情就会发生冲突。
如果没有SwipeRefreshLayout,也没问题
如果我周围有SwipeRefreshLayout,向上拖动的行为很奇怪,比如相反
https://gist.github.com/GHChrisSu/6aadf40dc693bc47cbb83a167a82a4b9
下面是运动场景
https://gist.github.com/GHChrisSu/a154d59f34555cccfc1b48617989ae16
发布于 2020-01-21 00:24:27
您应该将MotionLayout包装在SwipeRefreshLayout中,如下所示:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/play_scene">
<!-- Some xml code -->
</androidx.constraintlayout.motion.widget.MotionLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>然后,您必须将MotionLayout.TransitionListener添加到您的MotionLayout中,以根据MotionLayout状态对您的SwipeRefreshLayout执行enable/disable操作。
binding.motionLayout.setTransitionListener(object :MotionLayout.TransitionListener{
override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
}
override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
}
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {
Log.d("RepairsFragment","$p1 $p2 $p3")
if (p3 == 0f) {
binding.refresh.isEnabled=true
} else {
binding.refresh.isEnabled = false
binding.refresh.isRefreshing=false
}
}
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
}
})发布于 2019-03-31 20:03:20
我最终解决了这个问题,将SwipeRefreshLayout包装在motionlayout之外,并在onTransitionChange函数中更改SwipeRefreshLayout的状态来处理此问题
https://stackoverflow.com/questions/55411908
复制相似问题