2

所以我们试图模仿可窥视的行为BottomSheetLayout(从屏幕底部窥视的底部视图,向上滚动时进入全屏视图,有点像这样:https://www. youtube.com/watch?v=yrZVLL-z6P4 ) 使用MotionLayout, 版本2.0.0-alpha4.

问题是可OnSwipe窥视视图上的过渡不适用于视图本身,它显然适用于下面的整个视图,在这种情况下是 a RecyclerView. 因此,当我们滚动 时RecyclerView,过渡正在运行。

root_view.xml

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutDescription="@xml/motion_scene">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:clipToPadding="false"
            android:paddingBottom="@dimen/margin_48"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="@dimen/size_48"
            android:elevation="@dimen/elevation_12"
            android:gravity="center"
            app:layout_constraintBottom_toBottomOf="parent" />

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="@dimen/elevation_12"
            android:rotation="90"
            app:layout_constraintBottom_toBottomOf="@id/btn"
            app:layout_constraintEnd_toEndOf="@id/btn"
            app:layout_constraintTop_toTopOf="@id/btn" />

        <FrameLayout
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="@dimen/elevation_8"
            app:layout_constraintTop_toBottomOf="parent" />
    </androidx.constraintlayout.motion.widget.MotionLayout>
</FrameLayout>

motion_scene.xml

<Transition
    android:id="@+id/swipe"
    app:constraintSetEnd="@id/end"
    app:constraintSetStart="@id/start"
    app:duration="250">

    <OnSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@id/btn" />
</Transition>

<ConstraintSet android:id="@+id/start">

    <Constraint
        android:id="@id/fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="parent" />

    <Constraint
        android:id="@id/btn"
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_48"
        app:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">

    <Constraint
        android:id="@id/fragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/btn" />

    <Constraint
        android:id="@id/btn"
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_48"
        app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

4

2 回答 2

4

两者一起使用对app:touchAnchorId我有app:touchRegionId帮助。

<OnSwipe
    app:dragDirection="dragUp"
    app:touchAnchorId="@id/btn" 
    app:touchRegionId="@id/btn"/>
于 2020-06-08T12:43:13.587 回答
0

您必须禁用嵌套滚动以停止由 Recyclerview 触发的动画。执行以下操作,您会没事的:)

      <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/margin_48"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:nestedScrollingEnabled="false" />
于 2020-04-23T19:54:02.910 回答