我有Fragment
一个RecyclerView
在MotionLayout
. 在回收站视图之上,我有一个可以折叠和展开的视图,所有这些都在我的运动场景中完成。它由单击触发以及响应拖动回收站视图。到目前为止,这一切都按预期工作。
现在问题来了:我想在我的应用程序中完全隐藏某些状态的折叠视图。但是,如果我设置视图可见性或更改其高度,当我拖动回收器视图时,它仍然会重新出现。
那么是否可以完全禁用 MotionLayout(锁定约束),直到我再次启用它。禁用阻力识别器也是一个可行的解决方案。
现在用一些简化的 XML 来演示这种情况。
包含带有标题视图和回收器视图的运动布局的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.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"
...
/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
...
>
<androidx.recyclerview.widget.RecyclerVieww
android:id="@+id/favoritesList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.motion.widget.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”
implementation "com.android.support.constraint:constraint-layout:2.0.0-alpha3"
所以回顾一下:我希望能够禁用运动布局,这样我就可以在不扩展标题的情况下滚动回收视图,直到我告诉它再次启用。不幸的是,它并不像favouritesMotionLayout.isEnabled = false
,但这是我的想法。