使用 RecyclerView 作为 MotionLayout 的子项是否有问题?

Is there a problem is using a RecyclerView as a child of MotionLayout?

因此,我正在尝试创建一个由片段容器和其他两个视图组成的动画场景,以使用滑动手势进行播放。 问题是,只要片段容器包含回收器视图,并且存在 OnSwipe 转换,应用程序就会因空指针异常而崩溃。 这是我的代码

这是包含 MotionLayout 的主布局

    <?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/mainContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/activity_single_scene03"
    tools:context="com.mondiamedia.musicshop.activities.SingleActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/navHost"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true" />


    <include layout="@layout/layout_mini_player" />

    <include layout="@layout/layout_full_player" />
</androidx.constraintlayout.motion.widget.MotionLayout>

这是场景文件

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

    <ConstraintSet android:id="@+id/startSet">
        <Constraint
            android:id="@+id/miniPlayerContainer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.1"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintWidth_percent="0.9">
            <PropertySet android:alpha="1" />
        </Constraint>
        <Constraint
            android:id="@+id/fullPlayerContainer"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintTop_toBottomOf="parent">
            <PropertySet android:alpha="0" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/endSet">
        <Constraint
            android:id="@+id/miniPlayerContainer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.1"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintWidth_percent="0.9">
            <PropertySet android:alpha="0" />
        </Constraint>
        <Constraint
            android:id="@+id/fullPlayerContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <PropertySet android:alpha="1" />
        </Constraint>
    </ConstraintSet>

    <Transition
        app:constraintSetEnd="@id/endSet"
        app:constraintSetStart="@id/startSet"
        app:duration="1000">
        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorId="@id/miniPlayerContainer"
            app:touchAnchorSide="top"
            app:touchRegionId="@id/miniPlayerContainer" />
    </Transition>

    <Transition
        app:constraintSetEnd="@id/startSet"
        app:constraintSetStart="@id/endSet"
        app:duration="1000">
        <OnSwipe
            app:dragDirection="dragDown"
            app:touchAnchorId="@id/fullPlayerContainer"
            app:touchAnchorSide="top"
            app:touchRegionId="@id/fullPlayerContainer" />
    </Transition>

</MotionScene>

每当我在 navHost 片段中有一个 RecyclerView 并尝试滚动时,我都会遇到以下问题

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getId()' on a null object reference at androidx.constraintlayout.motion.widget.MotionLayout.onNestedPreScroll(MotionLayout.java:2200) at androidx.core.view.ViewParentCompat.onNestedPreScroll(ViewParentCompat.java:386) at androidx.core.view.NestedScrollingChildHelper.dispatchNestedPreScroll(NestedScrollingChildHelper.java:322) at androidx.recyclerview.widget.RecyclerView.dispatchNestedPreScroll(RecyclerView.java:11326) at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5061) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927) at android.view.Choreographer.doCallbacks(Choreographer.java:702) at android.view.Choreographer.doFrame(Choreographer.java:635) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

知道该怎么做以及为什么会这样吗?

似乎是 ConstraintLayout 版本 2.0.0-beta7 的问题

问题跟踪器 https://issuetracker.google.com/issues/158941179