如何animationanimation列表在Kotlin?

我有一个drawablesanimation list XML

      

我从我的content_main.xml调用了这个list

  

现在无论我用我的代码尝试,我无法启动animation。

在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() 

Kotlin类似于java …

//获取已经被编译到一个AnimationDrawable对象的背景。

 val frameAnimation: AnimationDrawable = img.background as AnimationDrawable 

//开始animation(默认循环播放)。

 frameAnimation.start() 

另一种方法是通过按ctrl + shift + a使用转换java代码到kotlin然后在行动feild,写下来

将Java转换成Kotlin ..

它会自动转换kotlin中的java代码。