MotionLayout - нажатие на макет ведет себя некорректно - PullRequest
0 голосов
/ 01 марта 2019

Для проекта я использую MotionLayout, все работает хорошо и гладко, за исключением одной мелочи.Когда я открываю приложение и нажимаю где-нибудь на экране, иногда макет переходит в неопределенное состояние.

Состояния, которые я определил, следующие: - приложение запускается с «разбитым белым» фоном - при смахивании вправо будет отображаться макет рамки с синим фоном - при смахивании макет кадра сбудет показан красный фон, скрывающий все остальные изображения imageView

Состояние, которое приложение принимает при нажатии где-либо на экране - появляется красный фон со всеми видимыми изображениями ViewView.

Я искалпричина того, почему это происходит, я думаю, что это ошибка (поскольку она все еще в альфа-версии), но хотел узнать мнение другого.

Код будет прикреплен, чтобы воспроизвести его довольно легко.

Основной макет:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<FrameLayout
        android:id="@+id/fl_forUnity"
        android:layout_width="match_parent"
        android:visibility="gone"
        android:layout_height="match_parent"
        android:alpha="1"
        tools:ignore="UnusedAttribute"/>

<androidx.constraintlayout.motion.widget.MotionLayout
        app:layoutDescription="@xml/scene_motion"
        android:id="@+id/topMotionLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <View
            android:id="@+id/backgroundView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <View
            android:id="@+id/ivBottomAnchor"
            android:layout_width="match_parent"
            android:layout_height="1dp"/>

    <FrameLayout
            android:id="@+id/flBottom"
            app:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <View
            android:id="@+id/ivLeftAnchor"
            android:layout_width="1dp"
            android:layout_height="match_parent"/>

    <FrameLayout
            android:id="@+id/flLeft"
            app:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
            android:layout_width="300dp"
            android:layout_height="match_parent"/>

    <View
            android:id="@+id/ivRightAnchor"
            android:layout_width="1dp"
            android:layout_height="match_parent"/>

    <FrameLayout
            android:id="@+id/flRight"
            app:layout_constraintStart_toEndOf="@id/ivRightAnchor"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>

    <ImageView
            android:layout_width="32dp"
            android:src="@drawable/ic_message"
            android:layout_height="32dp"
            tools:tint="@color/colorGreen_200"
            android:id="@+id/fabStartButton"/>

    <ImageView
            android:id="@+id/middleButton"
            tools:tint="@color/colorGreen_200"
            android:layout_width="64dp"
            android:src="@drawable/ic_circle"
            android:layout_height="64dp"/>

    <ImageView
            android:id="@+id/bottomButton"
            tools:tint="@color/colorGreen_200"
            android:layout_width="28dp"
            android:src="@drawable/ic_message"
            android:layout_height="28dp"/>

    <ImageView
            android:layout_width="32dp"
            android:layout_height="32dp"
            tools:tint="@color/colorGreen_200"
            android:src="@drawable/ic_adb"
            android:id="@+id/fabEndButton"/>

    <ImageView
            android:src="@drawable/ic_orb"
            android:id="@+id/ivOrb"
            tools:tint="@color/colorGreen_200"
            android:layout_width="6dp"
            android:layout_height="6dp"/>

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

Макет движения:

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

<Transition
        android:id="@+id/SwipeUp"
        motion:constraintSetStart="@+id/beginning"
        motion:constraintSetEnd="@+id/endAtTop">
    <OnSwipe
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@id/ivBottomAnchor"
            motion:touchAnchorSide="top"/>

    <KeyFrameSet>
        <KeyAttribute
                android:alpha="0"
                motion:framePosition="15"
                motion:target="@id/bottomButton"/>

        <KeyAttribute
                android:alpha="0"
                motion:framePosition="15"
                motion:target="@id/fabStartButton"/>

        <KeyAttribute
                android:alpha="0"
                motion:framePosition="15"
                motion:target="@id/middleButton"/>

        <KeyAttribute
                android:alpha="0"
                motion:framePosition="15"
                motion:target="@id/fabEndButton"/>

        <KeyAttribute
                motion:target="@id/backgroundView">
            <CustomAttribute
                    motion:attributeName="backgroundColor"
                    motion:customColorValue="#B71C1C"/>
        </KeyAttribute>
    </KeyFrameSet>
</Transition>

<Transition
        android:id="@+id/SwipeLeft"
        motion:constraintSetStart="@+id/beginning"
        motion:constraintSetEnd="@+id/endRighty">

    <OnSwipe
            motion:dragDirection="dragLeft"
            motion:touchAnchorId="@id/ivRightAnchor"
            motion:touchAnchorSide="top"/>
</Transition>

<Transition
        android:id="@+id/SwipeRight"
        motion:constraintSetStart="@+id/beginning"
        motion:constraintSetEnd="@+id/endLefty">

    <OnSwipe
            motion:dragDirection="dragRight"
            motion:touchAnchorId="@id/ivLeftAnchor"
            motion:touchAnchorSide="top"/>

    <KeyFrameSet>
        <KeyAttribute
                motion:target="@id/backgroundView">
            <CustomAttribute
                    motion:attributeName="backgroundColor"
                    motion:customColorValue="#0D47A1"/>
        </KeyAttribute>
    </KeyFrameSet>
</Transition>

<!--TODO: pressing on the bottombutton, go to bottom screen-->
<ConstraintSet android:id="@+id/beginning">
    <Constraint
            android:id="@+id/backgroundView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0"/>

    <Constraint
            android:id="@+id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"/>

    <Constraint
            android:id="@+id/ivBottomAnchor"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_height="1dp"
            android:layout_width="match_parent"/>

    <Constraint
            android:id="@+id/flBottom"
            motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivLeftAnchor"
            motion:layout_constraintStart_toStartOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flLeft"
            motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
            android:layout_width="300dp"
            android:layout_marginEnd="10dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flRight"
            android:layout_width="0dp"
            motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/fabStartButton"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_marginBottom="32dp"
            android:layout_marginStart="32dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/middleButton"
            android:layout_width="78dp"
            android:layout_height="78dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="72dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/bottomButton"
            android:layout_marginBottom="32dp"
            android:layout_width="28dp"
            android:layout_height="28dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/fabEndButton"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_marginBottom="32dp"
            android:layout_marginEnd="32dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"/>

    <Constraint
            android:id="@+id/ivOrb"
            android:layout_width="6dp"
            android:layout_height="6dp"
            android:visibility="gone"
            android:alpha="0"
            android:layout_marginTop="8dp"
            motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
            motion:layout_constraintStart_toStartOf="@id/middleButton"
            motion:layout_constraintEnd_toEndOf="@id/middleButton"/>
</ConstraintSet>

<ConstraintSet android:id="@+id/endAtTop">
    <Constraint
            android:id="@+id/backgroundView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="1"/>

    <Constraint
            android:id="@+id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"/>

    <Constraint
            android:id="@+id/ivBottomAnchor"
            android:layout_height="1dp"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_width="match_parent"/>

    <Constraint
            android:id="@+id/flBottom"
            motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivLeftAnchor"
            motion:layout_constraintStart_toStartOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flLeft"
            motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
            android:layout_width="300dp"
            android:layout_marginEnd="10dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flRight"
            android:layout_width="0dp"
            motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/fabStartButton"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:alpha="0"
            android:layout_marginBottom="32dp"
            android:layout_marginStart="80dp"
            android:translationY="-100dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/middleButton"
            android:layout_width="52dp"
            android:translationY="-100dp"
            android:alpha="0"
            android:layout_height="52dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="38dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/bottomButton"
            android:translationY="-100dp"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:alpha="0"
            motion:layout_constraintTop_toBottomOf="@id/middleButton"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/fabEndButton"
            android:layout_width="26dp"
            android:translationY="-100dp"
            android:alpha="0"
            android:layout_height="26dp"
            android:layout_marginBottom="32dp"
            android:layout_marginEnd="80dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"/>

    <Constraint
            android:id="@+id/ivOrb"
            android:visibility="gone"
            android:translationY="-100dp"
            android:layout_width="6dp"
            android:alpha="0"
            android:layout_height="6dp"
            android:layout_marginTop="8dp"
            motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
            motion:layout_constraintStart_toStartOf="@id/middleButton"
            motion:layout_constraintEnd_toEndOf="@id/middleButton"/>
</ConstraintSet>

<ConstraintSet android:id="@+id/endRighty">
    <Constraint
            android:id="@+id/backgroundView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0"/>

    <Constraint
            android:id="@+id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"/>

    <Constraint
            android:id="@+id/ivBottomAnchor"
            android:layout_height="1dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"/>

    <Constraint
            android:id="@+id/flBottom"
            motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivLeftAnchor"
            motion:layout_constraintStart_toStartOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flLeft"
            motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
            android:layout_width="300dp"
            android:layout_marginEnd="10dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivRightAnchor"
            motion:layout_constraintStart_toStartOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flRight"
            motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/fabStartButton"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:layout_marginBottom="32dp"
            android:layout_marginStart="80dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/middleButton"
            android:layout_width="52dp"
            android:layout_height="52dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="38dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/bottomButton"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:alpha="0"
            motion:layout_constraintTop_toBottomOf="@id/middleButton"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/fabEndButton"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:layout_marginBottom="32dp"
            android:layout_marginEnd="80dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"/>

    <Constraint
            android:id="@+id/ivOrb"
            android:layout_width="6dp"
            android:layout_height="6dp"
            android:layout_marginTop="8dp"
            motion:layout_constraintTop_toBottomOf="@id/fabEndButton"
            motion:layout_constraintStart_toStartOf="@id/fabEndButton"
            motion:layout_constraintEnd_toEndOf="@id/fabEndButton"/>
</ConstraintSet>

<ConstraintSet android:id="@+id/endLefty">
    <Constraint
            android:id="@+id/backgroundView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="1"/>

    <Constraint
            android:id="@+id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"/>

    <Constraint
            android:id="@+id/ivBottomAnchor"
            android:layout_height="1dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"/>

    <Constraint
            android:id="@+id/flBottom"
            motion:layout_constraintTop_toBottomOf="@id/ivBottomAnchor"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivLeftAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flLeft"
            motion:layout_constraintEnd_toStartOf="@id/ivLeftAnchor"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_height="match_parent"
            android:layout_width="1dp"/>

    <Constraint
            android:id="@+id/flRight"
            android:layout_width="0dp"
            motion:layout_constraintStart_toEndOf="@id/ivRightAnchor"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="@id/tbMain"
            android:layout_height="0dp"/>

    <Constraint
            android:id="@+id/fabStartButton"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:alpha="0"
            android:layout_marginBottom="32dp"
            android:layout_marginStart="80dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/middleButton"
            android:layout_width="52dp"
            android:layout_height="52dp"
            android:alpha="0"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="38dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/bottomButton"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:alpha="0"
            motion:layout_constraintTop_toBottomOf="@id/middleButton"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"/>

    <Constraint
            android:id="@+id/fabEndButton"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:alpha="0"
            android:layout_marginBottom="32dp"
            android:layout_marginEnd="80dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"/>

    <Constraint
            android:id="@+id/ivOrb"
            android:alpha="0"
            android:layout_width="6dp"
            android:layout_height="6dp"
            android:layout_marginTop="8dp"
            motion:layout_constraintTop_toBottomOf="@id/fabStartButton"
            motion:layout_constraintStart_toStartOf="@id/fabStartButton"
            motion:layout_constraintEnd_toEndOf="@id/fabStartButton"/>
</ConstraintSet>

1 Ответ

0 голосов
/ 07 июля 2019

Решением было дождаться новой версии motionLayout.В этом RC (я думаю, что это был RC3) была ошибка, связанная с состояниями видимости и тому подобным.На следующий RC (RC4) эта проблема была решена, и она работает как ожидалось.

...