手记

android开发:创建动态drawable

如何创建一个动态的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);
        }
    }
1人推荐
随时随地看视频
慕课网APP