Chr*_* Su 2 android swiperefreshlayout android-recyclerview android-motionlayout
当 RecyclerView 向上拖动时,我使用 MotionLayout 来实现一些很酷的效果,但看起来当我想将 SwipeRefreshLayout 与 RecyclerView 一起使用时,事情会发生冲突。
如果没有 SwipeRefreshLayout,那很好
如果我用 SwipeRefreshLayout 包围,向上拖动的行为就像反对一样奇怪
https://gist.github.com/GHChrisSu/6aadf40dc693bc47cbb83a167a82a4b9
运动场景如下
https://gist.github.com/GHChrisSu/a154d59f34555cccfc1b48617989ae16
小智 6
你应该换你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>
Run Code Online (Sandbox Code Playgroud)
然后,你必须添加MotionLayout.TransitionListener到您MotionLayout给enable/disable您SwipeRefreshLayout取决于MotionLayout状态。
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) {
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |