android开发 动态drawable的创建

不打扰是莪最后的温柔 提交于 2020-02-04 09:04:41

如何创建一个动态的drawable 图片如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
创建drawable

<?xml version="1.0" encoding="utf-8"?>
<animation-list
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:oneshot="false">
    <item android:drawable="@mipmap/audio_animation_list_left_1" android:duration="300"></item>
    <item android:drawable="@mipmap/audio_animation_list_left_2" android:duration="300"></item>
    <item android:drawable="@mipmap/audio_animation_list_left_3" android:duration="300"></item>
</animation-list>

运行动态图片的代码

private void play() {
    if (animationView.getBackground() instanceof AnimationDrawable) {
        AnimationDrawable animation = (AnimationDrawable) animationView.getBackground();
        animation.start();
    }
}

private void stop() {
    if (animationView.getBackground() instanceof AnimationDrawable) {
        AnimationDrawable animation = (AnimationDrawable) animationView.getBackground();
        animation.stop();
        animation.selectDrawable(2);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!