Как переместить элемент наверх и воткнуть его сюда в макете движения? - PullRequest
0 голосов
/ 25 мая 2019

Во время прокрутки я хочу переместить кнопку из нижней части AppBarLayout в верхнюю часть экрана. однако, если я установил ограничение motion:layout_constraintTop_toTopOf="parent", кнопка отходит от экрана из-за того, что AppBarLayout тоже перемещается. Как справиться с такой ситуацией?

motionscene

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">
    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="1000"
        motion:motionInterpolator="linear">
        <KeyFrameSet>
            <KeyPosition
                motion:framePosition="25"
                motion:motionTarget="@+id/m_button"
                motion:percentX="1"
                motion:percentY="1" />
        </KeyFrameSet>
        <ConstraintSet android:id="@+id/start">
            <Constraint
                android:id="@+id/m_button"
                android:layout_width="60dip"
                android:layout_height="40dip"
                android:layout_marginTop="24dip"
                android:layout_marginEnd="16dip"
                android:layout_marginBottom="24dip"
                motion:layout_constraintBottom_toBottomOf="parent" />
        </ConstraintSet>
        <ConstraintSet android:id="@+id/end">
            <Constraint
                android:id="@id/m_button"
                android:layout_width="60dip"
                android:layout_height="40dip"
                android:layout_marginTop="24dip"
                android:layout_marginEnd="16dip"
                android:layout_marginBottom="24dip"
                android:translationX="0dp"
                android:translationY="100dp"
                motion:layout_constraintTop_toTopOf="parent" />
        </ConstraintSet>
    </Transition>
</MotionScene>

расположение

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/contentBackground"
    android:fitsSystemWindows="false">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="500dip"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.androidstudio.motionlayoutexample.utils.CollapsibleToolbar xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/motionLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#1e376b"
            android:minHeight="88dip"
            app:layoutDescription="@xml/motion"
            app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed">


            <Button
                android:id="@+id/m_button"
                android:layout_width="60dip"
                android:layout_height="40dip" />

        </com.google.androidstudio.motionlayoutexample.utils.CollapsibleToolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/scrollable"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:text="1\n2\n\3\n4\n5\n6\n7\n8\n\9\n10\n11\n12\n13\n\14\n1\n2\n\3\n4\n5\n6\n7\n8\n\9\n10\n11\n12\n13\n\14" />

    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

1 Ответ

0 голосов
/ 03 июня 2019

есть некоторые элементы управления Layout, которые обрабатывают ограничение пропущенных видов. например,

 `motion:layout_goneMarginBottom`

Надеюсь, это поможет вам встать на правильный путь.

...