第一次向上滚动时播放部分motionLayout动画

时间:2019-06-20 19:39:56

标签: android animation kotlin android-motionlayout

我使用MotionLayout为根据RecyclerView滚动条的自定义工具栏制作动画。当我加载屏幕并向下滚动RecyclerView时,一切正常。 但是!如果我开始加载屏幕并向上滚动(没有RecyclerView元素),则动画会部分播放,TextView将字体大小和水平对齐方式(不是垂直)恢复到最终状态,第二个TextView也会进入最终状态,但同时工具栏不会更改大小。

另外,在加载屏幕时,它不会进入constraintSetStart中描述的状态

布局文件     

    <View
        android:id="@+id/blaBlaBackground"
        android:layout_width="@dimen/base_0dp"
        android:layout_height="192dp"
        android:layout_marginBottom="192dp"
        android:background="@drawable/bg"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/ivIconBackBlaBla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:src="@drawable/ic_close_white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/tvToolbarTitleBlaBla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/base_16dp"
        android:layout_marginTop="56dp"
        android:fontFamily="@font/notosans_light"
        android:letterSpacing="-0.02"
        android:text="@string/label_create_order"
        android:textColor="@color/white"
        android:textSize="@dimen/base_24sp"
        app:layout_constraintBottom_toTopOf="@+id/rvBlaBlaScrollingContent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/tvToolbarSubtitleBlaBla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:fontFamily="@font/notosans_regular"
        android:letterSpacing="0.01"
        android:text="@string/label_pickup_details"
        android:textColor="@color/white"
        android:textSize="@dimen/base_14sp"
        app:layout_constraintStart_toStartOf="@id/tvToolbarTitleBlaBla"
        app:layout_constraintTop_toBottomOf="@id/tvToolbarTitleBlaBla" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/tvCancelActionBlaBla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/base_16dp"
        android:fontFamily="@font/notosans_regular"
        android:gravity="center"
        android:text="@string/cancel"
        android:textColor="@color/white"
        android:textSize="@dimen/base_16sp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@id/ivIconBackBlaBla"
        tools:visibility="visible" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvBlaBlaScrollingContent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/bg_scrolling_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/blaBlaBackground" />

</com.mgx.app.launch.authorized.navigation.orders.create.participants.ParticipantLayout>

描述文件

<?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"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetEnd="@id/collapsed"
        motion:constraintSetStart="@id/expanded">
        <OnSwipe
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@+id/rvBlaBlaScrollingContent"
            motion:touchAnchorSide="top" />
    </Transition>


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

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

        <Constraint
            android:id="@id/BlaBlaBackground"
            android:layout_width="@dimen/base_0dp"
            android:layout_height="56dp"
            android:layout_marginBottom="192dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <Constraint
            android:id="@+id/ivIconBackBlaBla"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="@dimen/base_16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/tvToolbarTitleBlaBla"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="61dp"
            android:layout_marginTop="@dimen/base_0dp"
            android:scaleX="0.84"
            android:scaleY="0.84"
            app:layout_constraintBottom_toTopOf="@id/rvBlaBlaScrollingContent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/tvToolbarSubtitleBlaBla"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/base_16dp"
            android:visibility="invisible"
            app:layout_constraintStart_toStartOf="@id/ivIconBackBlaBla"
            app:layout_constraintTop_toBottomOf="@id/tvToolbarTitleBlaBla" />

        <Constraint
            android:id="@+id/rvBlaBlaScrollingContent"
            android:layout_marginTop="56dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </ConstraintSet>

</MotionScene>

0 个答案:

没有答案