MotionLayout Проведите пальцем влево и вправо, проблема с анимацией - PullRequest
0 голосов
/ 28 марта 2020

Я создаю макет движения, в котором пользователь может провести пальцем влево или вправо, когда я добавил, layoutDescription layout-width больше не работает. Я хочу, чтобы иметь возможность изменить размер android:layout_width макета на пролистывание. Вот мои XML для MotionScene и MotionLayout

   <androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layoutDescription="@xml/table_view_odd_list_shuffle"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="@id/guideline5"
                    app:layout_constraintTop_toBottomOf="@id/constraint_layout_spinners">

                    <RelativeLayout
                        android:id="@+id/relative_layout_odds_column"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

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

                            <androidx.recyclerview.widget.RecyclerView
                                android:id="@+id/table_view_recycle_view_odds_1"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:nestedScrollingEnabled="false"
                                android:orientation="horizontal"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toStartOf="@id/table_view_recycle_view_odds_2"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent" />

                            <androidx.recyclerview.widget.RecyclerView
                                android:id="@+id/table_view_recycle_view_odds_2"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:nestedScrollingEnabled="false"
                                android:orientation="horizontal"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toEndOf="@id/table_view_recycle_view_odds_1"
                                app:layout_constraintTop_toTopOf="parent" />

                            <androidx.constraintlayout.widget.Guideline
                                android:id="@+id/guideline6"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:orientation="vertical"
                                app:layout_constraintGuide_percent="0.5"
                                app:layout_constraintTop_toBottomOf="parent" />
                        </androidx.constraintlayout.widget.ConstraintLayout>
                    </RelativeLayout>
                </androidx.constraintlayout.motion.widget.MotionLayout>

MotionScene xml

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <!-- center to left-->
    <Transition
        motion:constraintSetEnd="@id/left"
        motion:constraintSetStart="@id/center"
        motion:duration="200">
        <OnSwipe
            motion:dragDirection="dragLeft"
            motion:touchAnchorId="@id/relative_layout_odds_column"
            motion:touchAnchorSide="left" />
    </Transition>
    <!-- center to right -->
    <Transition
        motion:constraintSetEnd="@id/right"
        motion:constraintSetStart="@id/center"
        motion:duration="200">
        <OnSwipe
            motion:dragDirection="dragRight"
            motion:touchAnchorId="@id/relative_layout_odds_column"
            motion:touchAnchorSide="right" />
    </Transition>

    <ConstraintSet android:id="@+id/center">
        <Constraint
            android:id="@id/relative_layout_odds_column"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent">
            <PropertySet android:alpha="1" />
        </Constraint>
    </ConstraintSet>
    <!-- place the view on left-->
    <ConstraintSet android:id="@+id/left">
        <Constraint
            android:id="@id/relative_layout_odds_column"
            android:layout_width="10dp"
            android:layout_height="match_parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent">
            <PropertySet android:alpha="1" />
        </Constraint>
    </ConstraintSet>
    <!-- place the view on right-->
    <ConstraintSet android:id="@+id/right">
        <Constraint
            android:id="@id/relative_layout_odds_column"
            android:layout_width="10dp"
            android:layout_height="match_parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toTopOf="parent">
            <PropertySet android:alpha="1" />
        </Constraint>
    </ConstraintSet>


</MotionScene>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...