Mik*_*yan 2 android background android-animation kotlin
我有一个animation list XML在drawables:
<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>
Run Code Online (Sandbox Code Playgroud)
我打电话list给我content_main.xml:
<ImageView
...
android:id="@+id/animatedPerson"
android:src="@drawable/animatedperson"
...
/>
Run Code Online (Sandbox Code Playgroud)
现在无论我尝试使用我的代码,我都无法启动动画.
在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();
Run Code Online (Sandbox Code Playgroud)
所以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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1450 次 |
| 最近记录: |