当我用RecyclerView和SwipeRefreshLayout在MotionLayout中做一些动画时,这件事变得很奇怪

时间:2019-03-29 06:49:44

标签: android android-recyclerview swiperefreshlayout android-motionlayout

当RecyclerView向上拖动时,我正在使用MotionLayout达到一些很酷的效果,但是当我想将SwipeRefreshLayout与RecyclerView一起使用时,事情就变得冲突了。

如果没有SwipeRefreshLayout,那就很好

如果我被SwipeRefreshLayout包围,则向上拖动行为就很奇怪

https://gist.github.com/GHChrisSu/6aadf40dc693bc47cbb83a167a82a4b9

动作场景在下面

https://gist.github.com/GHChrisSu/a154d59f34555cccfc1b48617989ae16

2 个答案:

答案 0 :(得分:5)

您应将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的{​​{1}}中添加enable/disableSwipeRefreshLayout

MotionLayout

答案 1 :(得分:0)

最后,我将SwipeRefreshLayout包装在运动布局之外,并在onTransitionChange函数中更改SwipeRefreshLayout的状态以解决此问题,以解决此问题