美文网首页
android Drawable Animation(帧动画)

android Drawable Animation(帧动画)

作者: hao_developer | 来源:发表于2021-01-15 15:15 被阅读0次

1.帧动画概述:
帧动画是顺序播放一组预先定义好的图片,不同于View动画,系统提供了另外一个类AnimationDrawable来使用帧动画。
2.帧动画的使用
首先我们找一组帧动画的图片放入drawable-xhdpi文件夹下,其次在drawable文件夹下创建xml文件,如下所示:

<?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/refresh1" android:duration="180"/>
    <item android:drawable="@drawable/refresh2" android:duration="180"/>
    ...
    <item android:drawable="@drawable/refresh25" android:duration="180"/>
</animation-list>
view = findViewById(R.id.view);
        view.setBackgroundResource(R.drawable.drawable_anim);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnimationDrawable animationDrawable = (AnimationDrawable) view.getBackground();
                animationDrawable.start();
            }
        });

通过上述代码,帧动画已经完成了,我们来看下效果图:


image.png

\color{red}{<animation-list>}\必须是根节点,包含一个或者多个\color{red}{<item>}\元素,属性有:
\color{red}{android:oneshot true}\代表只执行一次,false循环执行。
\color{red}{<item>}\类似一帧的动画资源。

\color{red}{<item>}\animation-list的子项,包含属性如下:
\color{red}{android:drawable}\一个frame的Drawable资源。
\color{red}{android:duration}\一个frame显示多长时间。

相关文章

网友评论

      本文标题:android Drawable Animation(帧动画)

      本文链接:https://www.haomeiwen.com/subject/gdlwaktx.html