微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NestedScrollView点击触发Motionlayout

如何解决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 举报,一经查实,本站将立刻删除。