gpt4 book ai didi

android - 如何在 Kotlin 中为动画列表设置动画?

转载 作者:太空狗 更新时间:2023-10-29 16:27:47 24 4
gpt4 key购买 nike

我在 drawables 中有一个动画列表 XML:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:duration="40" android:drawable="@drawable/animated_person_0 />
<item android:duration="40" android:drawable="@drawable/animated_person_1 />
<item android:duration="40" android:drawable="@drawable/animated_person_2 />
</animated-list>

我从我的 content_main.xml 调用了 list:

<ImageView
...
android:id="@+id/animatedPerson"
android:src="@drawable/animatedperson"
...
/>

现在无论我用我的代码尝试什么,我都无法启动动画。

最佳答案

在 Java 中是这样的:

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

// Start the animation (looped playback by default).
frameAnimation.start();

所以 Kotlin 会非常相似:

// Get the background, which has been compiled to an AnimationDrawable object.
val frameAnimation: AnimationDrawable = img.background as AnimationDrawable

// Start the animation (looped playback by default).
frameAnimation.start()

关于android - 如何在 Kotlin 中为动画列表设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45585866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com