是否可以禁用MotionLayout? [英] Is it possible to disable MotionLayout?

查看:166
本文介绍了是否可以禁用MotionLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Fragment ,该片段在 MotionLayout中托管一个 RecyclerView 。在回收者视图的顶部,我有一个可以折叠和展开的视图,所有这些都在我的运动场景中完成。它是通过单击触发的,并且响应拖动回收站视图。

I'v got a Fragment that hosts a RecyclerView within a MotionLayout. On top of the recycler view I've got a view that collapses and expands, all done in my motion scene. It is triggered by a click as well as responding to dragging the recycler view. So far this all works as intended.

现在到了症结所在:我想在我的应用程序中完全隐藏某些州的崩溃视图。
但是,如果我设置视图的可见性或更改其高度,则在拖动recyclerview时它仍然会重新显示。

Now comes the crux: I'd like to hide the collapsing views completely for some states within my app. But if I set the views visibility or change its height, it still comes back into view when I drag the recyclerview.

因此可以禁用完全启用MotionLayout(锁定约束),直到再次启用它为止。禁用拖动识别器也是一种可行的解决方案。

So is it possible to disable the MotionLayout completely (Lock the constraints) until I enable it again. To disable the drag recogniser would also be a viable solution.

现在使用一些简化的XML来演示这种情况。

Now some simplified XML to demonstrate the situation.

该布局包含带有标题视图和recyclerview的运动布局

The layout containing the motion layout with header view and recyclerview

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/favouritesMotionLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/favourites_motion_scene"
    android:animateLayoutChanges="true">

    <ImageView
        android:id="@+id/headerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...
        />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        ...
    >

        <pinch.nrcnext.view.scroll.NRCRecyclerView
            android:id="@+id/favoritesList"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.constraint.motion.MotionLayout>

相应的运动场景:

<?xml version="1.0" encoding="utf-8"?>
<MotionScene
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto"
>

    <Transition
        motion:constraintSetStart="@id/expanded"
        motion:constraintSetEnd="@id/collapsed"
        motion:duration="300">
        <OnSwipe
            motion:touchAnchorId="@id/swipeRefreshLayout"
            motion:touchAnchorSide="top"
            motion:dragDirection="dragUp" />
    </Transition>

    <ConstraintSet android:id="@+id/expanded">
        ... Constraints for expanded header ...
    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">
        ... ... Constraints for collapsed header ...
    </ConstraintSet>

</MotionScene>

使用约束布局版本 2.0.0-alpha3

Using constraint layout version "2.0.0-alpha3"

实现 com.android.support.constraint:constraint-layout:2.0.0-alpha3

所以回顾一下:我希望能够禁用运动布局,以便我可以滚动recyclerview而不扩展标题,直到我告诉它再次启用为止。
不幸的是,它并不像 favouritesMotionLayout.isEnabled = false 那样容易,但这就是我的想法。

So recap: I'd like to be able to disable the motion layout, so that I can scroll the recyclerview without the header expanding, until I tell it to be enabled again. Unfortunately it is not as easy as favouritesMotionLayout.isEnabled = false, but that is the way I was thinking.

推荐答案

现在有了ConstraintLayout beta 2,您可以了!这是执行此操作的官方方法:

Now with ConstraintLayout beta 2 you can! This is the official way to do it:

motionLayout.getTransition(R.id.yourTransition).setEnable(false)

这篇关于是否可以禁用MotionLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆