Как возможно выбрать одну из нескольких сцен в MotionLayout?

Допустим, у меня есть несколько сцен app:layoutDescription="@xml/game_start_xml_colo_scene2" , кроме этой еще 1 и 3.

Как в коде я могу я задать выбор этих сцен?

        <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/Colo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chars_layout"
        android:layout_below="@+id/topLayout"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        android:background="@drawable/main_game_board"
        app:layoutDescription="@xml/game_start_xml_colo_scene2">

Ответы (1 шт):

Автор решения: Vlad Orlinskas

MotionLayout содержит метод setScene(MotionScene scene). Вам необходимо создать сцену с помощью конструктора MotionScene(Context context, MotionLayout layout, int resourceID)

Пример кода kotlin:

motionLayout.setScene(MotionScene(context, motionLayout, R.xml.my_scene))
→ Ссылка