MotionLayout onSwipe中断动画

时间:2019-05-17 16:56:13

标签: android android-layout android-animation android-constraintlayout android-motionlayout

我想根据recyclerView的滚动条制作折叠的背景。如果在单击按钮时启动动画,则一切正常,但如果在滚动时启动动画,则动画将立即进入没有动画的最终状态。 video desc

ffffffffffffffffffffffffffffffffffffffffffff

布局

<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"
android:background="@color/gray_more_white"

app:layoutDescription="@xml/collapsing_toolbar"
app:applyMotionScene="true"
app:showPaths="true">

<include
    android:id="@+id/include"
    layout="@layout/toolbar"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.github.florent37.shapeofview.shapes.ArcView
    android:id="@+id/header_view"
    android:layout_width="0dp"
    android:layout_height="100dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/include"
    app:shape_arc_cropDirection="outside"
    app:shape_arc_height="20dp"
    app:shape_arc_position="bottom">

    <View
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark" />

</com.github.florent37.shapeofview.shapes.ArcView>

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/include" />


<!--unrelated to questions-->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipe_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/include"

    android:visibility="gone">

    <!--<androidx.recyclerview.widget.RecyclerView-->
        <!--android:id="@+id/recyclerView"-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="match_parent" />-->

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

MotionScene

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<Transition
    app:constraintSetStart="@id/start"
    app:constraintSetEnd="@id/end"
    app:duration="500">

    <OnSwipe
        app:dragDirection="dragDown"
        app:moveWhenScrollAtTop="true"
        app:touchAnchorId="@id/recyclerView"
        app:touchAnchorSide="bottom"
        app:touchRegionId="@id/recyclerView"
        app:onTouchUp="autoComplete"/>

</Transition>

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

</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint android:id="@id/header_view"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </Constraint>
</ConstraintSet>

0 个答案:

没有答案