MotionLayout в android не работает с несколькими переходами OnClick

У меня проблема с MotionLayout. Я создал сцену, и она работает, когда я использую один переход onClick. Но мне нужно два.

Я хочу сделать следующее: при нажатии на кнопку в представлении одно это представление будет скрыто, а другое представление отобразится. Это работает. Но теперь, когда я нажимаю кнопку в другом представлении, я хочу показать первое представление, а второе нужно скрыть.

Такого рода работает, только проблема в том, что он не работает с переходом. Это просто видно.

Моя сцена выглядит так:

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

<Transition
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@+id/start"
    motion:duration="2000"
    motion:motionInterpolator="easeOut">
    <OnClick
        motion:clickAction="transitionToEnd"
        motion:targetId="@+id/hide_menu" />
</Transition>

<Transition
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@+id/start"
    motion:duration="2000"
    motion:motionInterpolator="easeInOut">
    <OnClick
        motion:clickAction="transitionToStart"
        motion:targetId="@+id/quick_menu_show_menu" />
</Transition>

<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@+id/sidebar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:translationX="0dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />

    <Constraint
        android:id="@+id/quick_menu"
        android:layout_width="19dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="4dp"
        android:translationX="-70dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@+id/sidebar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:translationX="-70dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />

    <Constraint
        android:id="@+id/quick_menu"
        android:layout_width="19dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="4dp"
        android:translationX="0dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

</MotionScene>

надеюсь, что кто-нибудь может помочь.

С уважением,

JKorsten


person Jeroen    schedule 12.07.2019    source источник


Ответы (1)


По какой-то причине это решает проблему, но я надеюсь, что кто-то сможет объяснить, почему это так.

<Transition
    motion:constraintSetEnd="@+id/start"
    motion:constraintSetStart="@+id/end"
    motion:duration="2000"
    motion:motionInterpolator="easeIn">
    <OnClick
        motion:clickAction="transitionToStart"
        motion:targetId="@+id/quick_menu_show_menu" />
</Transition>

Насколько я читал, он легко переходит от ConstraintSetEnd к ConstraintSetStart (transitionToStart), но мне нужно было изменить ConstraintSetEnd на @ + id / start и ConstraintSetStart на @ + id / end.

person Jeroen    schedule 12.07.2019