NestedScrollView点击触发Motionlayout

问题描述

我对MotionLayout的更新版本低于2.0.0-beta8感到困惑。它观察到,更新库后,MotionLayout的行为以及nestedScrollView / RecycleView发生了变化。 我正在使用运动布局来模拟“折叠”工具栏,该工具栏在折叠模式下应显示两张卡片。每张卡都有自己的内容和行为。

问题 当您折叠标题(工具栏)并单击其下方的内容时,它将标题向后展开。

这是我的标题内容

<?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:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/main_motion_layout"
tools:context=".MainActivity">

<View
    android:id="@+id/headerBg"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/colorPrimary"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.core.widget.nestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/headerBg">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_margin="10dp"
            android:background="@color/colorAccent" />

        <View
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_margin="10dp"
            android:background="@color/colorPrimaryDark" />
    </LinearLayout>
</androidx.core.widget.nestedScrollView>

下面,您可以找到我的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">

<Transition
    app:constraintSetEnd="@id/collapsed"
    app:constraintSetStart="@id/expanded"
    app:duration="1000"
    app:motionInterpolator="linear">

    <OnSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@id/headerBg"
        app:touchAnchorSide="bottom" />


</Transition>

<ConstraintSet android:id="@+id/expanded">
</ConstraintSet>
<ConstraintSet android:id="@+id/collapsed">

    <Constraint
        android:id="@id/headerBg"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

如果我将nestedScrollView更改为RecycleView,则行为是相同的。 如果将nestedScrollView更改为ScrollView,则可以解决单击问题,但是现在无法完全展开标题了。 使用版本为2.0.0-beta8的库时,一切正常,但我需要根据业务规则进行更新。

任何想法或建议。 预先谢谢你

下面您可以找到完整的测试代码https://github.com/rsalomao2/motionlayout/tree/motion_nestedscrollview

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)