小编Ish*_*edi的帖子

自动转换在 Motion 布局中不起作用

我目前正在学习动作布局。我创建了一个小应用程序,其中中心的图像旋转 5 秒。onClick 和 onSwipe 属性在设备上工作正常,但使用 autotransition = animateToEnd 当我在设备上运行应用程序时没有任何反应。基本上我希望我的转换在活动开始时自动发生。这是我的运动布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/activity_main_scene">

    <ImageView
        android:id="@+id/back"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="TODO"
        android:src="@drawable/background" />

    <ImageView
        android:id="@+id/moon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_moon"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的运动场景:

<?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="5000"
        motion:autoTransition="animateToEnd">
       <KeyFrameSet>
           <KeyCycle
               motion:motionTarget="@+id/moon"
               motion:framePosition="0"
               motion:wavePeriod="2"
               motion:waveShape="sawtooth"
               android:rotation="180"
               motion:waveOffset="0" />
       </KeyFrameSet>
    </Transition>

    <ConstraintSet android:id="@+id/start">
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
    </ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)

如果有任何替代方法可以通过运动布局运行过渡,请告诉我们。**为了运行应用程序,我曾经创建调试 apk,然后在我的设备上运行它。

android android-motionlayout

4
推荐指数
1
解决办法
3820
查看次数

标签 统计

android ×1

android-motionlayout ×1