我是靠谱客的博主 坦率美女,这篇文章主要介绍java控制一套动效图播放、暂停和重置的方法,现在分享给大家,希望可以做个参考。

UI 出一套动效图一般来说有25张左右,如何控制这些图片自动的依次循环播放且能随时暂停和重置呢?我在看别人代码时看到了这样一个方法:


1.在 drawable 目录下新建一个animation-list,名字任取,比如说命名为play_btn_animation_list,把图片资源放入循环列表,从第一张到第二十五张,其中android:oneshot="false"表示循环播放,若设置为true则只播放一次,不会循环播放,android:duration用来指定每一帧的播放持续时间;


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >

    <item
        android:drawable="@drawable/recorder_anmation_1"
        android:duration="20">
    </item>
    <item
        android:drawable="@drawable/recorder_anmation_2"
        android:duration="20">
    </item>

中间图片省略......

    <item
        android:drawable="@drawable/recorder_anmation_24"
        android:duration="20">
    </item>
    <item
        android:drawable="@drawable/recorder_anmation_25"
        android:duration="20">
    </item>

</animation-list>

2.在Activity新建一个AnimationDrawable对象:

private AnimationDrawable animationDrawable;

3.初始化 AnimationDrawable 对象和用来显示该动画的ImageView控件并使其显示循环动画图片集合中的第一张图:

mStart_bg_state = (ImageView) findViewById(R.id.play_btn_state);
mStart_bg_state.setBackground(getResources().getDrawable(R.drawable.play_btn_animation_list));
animationDrawable = (AnimationDrawable) mStart_bg_state.getBackground();

4.开始依次播放:

animationDrawable.start();

5.暂停播放:

animationDrawable.stop();

6.重置,恢复显示第一张:

mStart_bg_state.setBackground(getResources().getDrawable(R.drawable.play_btn_animation_list));
animationDrawable = (AnimationDrawable) mStart_bg_state.getBackground();

最后

以上就是坦率美女最近收集整理的关于java控制一套动效图播放、暂停和重置的方法的全部内容,更多相关java控制一套动效图播放、暂停和重置内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部