MotionLayout не будет анимироваться с MotionScene - PullRequest
0 голосов
/ 19 января 2020

Я пытаюсь создать собственную свертывающуюся панель инструментов с помощью Motion Layout. Когда пользователь прокручивает, Lo go должен анимироваться в меньший размер на панель инструментов. После реализации здесь

я настроил свой макет и свой MotionScene. По какой-то странной причине я никогда не видел анимацию панели инструментов, когда я прокручивал в NestedScrollView. Может быть, я что-то упустил в моем MotionScene xml.

Вот макет:

<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:id="@+id/cities_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layoutDescription="@xml/collapsing_toolbar"
>

<androidx.appcompat.widget.Toolbar
    android:id="@+id/city_list_toolbar"
    android:layout_width="0dp"
    android:layout_height="84dp"
    app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/city_list_logo"
    android:layout_width="wrap_content"
    android:layout_height="84dp"
    android:contentDescription="@string/content_description_resource_general"
    android:padding="8dp"
    android:src="@drawable/icon_lp_logo_blue"
    app:layout_constraintBottom_toBottomOf="@id/city_list_toolbar"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/city_list_search"
    style="@style/ResizingActionbarIcon"
    android:layout_margin="4dp"
    android:contentDescription="@string/content_description_resource_general"
    android:src="@drawable/icon_search"
    android:visibility="invisible"
    app:layout_constraintBottom_toTopOf="@id/city_fragment_city_holder"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:visibility="visible" />


    <ImageView
        android:id="@+id/city_list_toolbar_shadow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/content_description_resource_general"
        android:src="@drawable/lp_action_bar_shadow"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/city_list_toolbar" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/city_fragment_city_holder"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="8dp"
    android:fillViewport="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/city_list_toolbar"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/cities_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/city_list_search_container"
            android:layout_width="match_parent"
            android:layout_height="52dp"
            android:background="?android:attr/selectableItemBackground"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/city_list_search_input"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableStart="@drawable/icon_search_gray_small"
                android:drawablePadding="8dp"
                android:fontFamily="@font/sans_regular"
                android:hint="@string/hint_search_cities"
                android:maxLines="1"
                android:textAlignment="center"
                android:textColorHint="@color/second_copy"
                android:textSize="16sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <ImageView
            android:id="@+id/city_list_toolbar_shadow"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/content_description_resource_general"
            android:src="@drawable/lp_action_bar_shadow"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/city_list_search_container" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/cities_collection_top_recycler_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:clipToPadding="false"
            android:paddingStart="20dp"
            android:paddingEnd="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/city_list_search_container" />

        <TextView
            android:id="@+id/cities_recently_title"
            style="@style/must_see_title_style"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="20dp"
            android:text="@string/home_recently_viewed"
            app:layout_constraintEnd_toStartOf="@+id/cities_recently_see_all"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_collection_top_recycler_view" />

        <TextView
            android:id="@+id/cities_recently_see_all"
            style="@style/see_all_text_style"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:clickable="true"
            android:drawableEnd="@drawable/icon_arrow_right_blue"
            android:focusable="true"
            android:gravity="center_vertical"
            android:text="@string/see_all"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="@+id/cities_recently_title"
            app:layout_constraintEnd_toEndOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/cities_recently_recycler_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:clipToPadding="false"
            android:paddingStart="20dp"
            android:paddingEnd="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_recently_title" />

        <TextView
            android:id="@+id/cities_top_guides_title"
            style="@style/must_see_title_style"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="20dp"
            android:text="@string/home_top"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_recently_recycler_view" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/cities_top_guides_title_recycler_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:clipToPadding="false"
            android:paddingStart="20dp"
            android:paddingEnd="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_top_guides_title" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/cities_sponsored_collections_recycler_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:clipToPadding="false"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_top_guides_title_recycler_view" />

        <TextView
            android:id="@+id/cities_by_region_title"
            style="@style/must_see_title_style"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="20dp"
            android:text="@string/home_by_region"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_sponsored_collections_recycler_view" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/cities_by_region_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:overScrollMode="never"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cities_by_region_title" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.motion.widget.MotionLayout>

Вот мой MotionScene xml файл:

<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">

    <onSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@+id/city_fragment_city_holder"
        app:touchAnchorSide="top"/>
</Transition>

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

<Constraint
        android:id="@+id/city_list_logo"
        android:layout_width="wrap_content"
        android:layout_height="84dp"
        android:scaleX="1.0"
        android:scaleY="1.0"
        app:layout_constraintBottom_toBottomOf="@+id/city_list_toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        >
    </Constraint>

    <Constraint
        android:id="@+id/city_list_toolbar"
        android:layout_width="0dp"
        android:layout_height="84dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />
</ConstraintSet>

<ConstraintSet android:id="@+id/collapsed">
    <Constraint
        android:id="@+id/city_list_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX=".35"
        android:scaleY=".35"
        app:layout_constraintBottom_toBottomOf="@+id/city_list_toolbar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/city_list_toolbar">

        </Constraint>

    <Constraint
        android:id="@+id/city_list_toolbar"
        android:layout_height="?attr/actionBarSize"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />
</ConstraintSet>
</MotionScene>
...