首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我用MotionLayout和RecyclerView和SwipeRefreshLayout做一些动画时,这件事变得很奇怪

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

Stack Overflow用户
提问于 2019-03-29 14:49:44
回答 2查看 1.5K关注 0票数 2

当RecyclerView拖起时,我使用MotionLayout来实现一些很酷的效果,但是当我想在RecyclerView中使用SwipeRefreshLayout时,事情就会发生冲突。

如果没有SwipeRefreshLayout,也没问题

如果我周围有SwipeRefreshLayout,向上拖动的行为很奇怪,比如相反

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

下面是运动场景

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

EN

回答 2

Stack Overflow用户

发布于 2020-01-21 00:24:27

您应该将MotionLayout包装在SwipeRefreshLayout中,如下所示:

代码语言:javascript
复制
    <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操作。

代码语言:javascript
复制
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) {
        }
    })
票数 6
EN

Stack Overflow用户

发布于 2019-03-31 20:03:20

我最终解决了这个问题,将SwipeRefreshLayout包装在motionlayout之外,并在onTransitionChange函数中更改SwipeRefreshLayout的状态来处理此问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55411908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档