zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

android开发 动态drawable的创建

Android开发 创建 动态 Drawable
2023-09-14 09:05:10 时间

如何创建一个动态的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);
    }
}