android动画之逐帧动画的特点以及使用方法

一:简介:

    android的动画类型分为两种:

                  1.视图动画

                  2.属性动画

其中,视图动画又分为逐帧动画补间动画。 

今天我们主要来学习一下逐帧动画的特点和使用方法:

逐帧动画特点:

逐帧动画是一种常见的动画形式,其原理是在“连续的关键帧“中分解动画动作,也就是在时间轴上的每帧上逐帧绘制不用的内容,使其连续播放而成动画,播放动画具有非常大的灵活性,几乎可以表现任何想表现的内容。

但是由于逐帧动画的帧序列内容不一样,不仅增加制作负担,而且最终输出的文件量也很大,但是它的优势也很明显:因为它与电影播放模式相似,很适合表演很细腻的动画,如人物或动物急剧转身、头发及衣服的飘动、走路、说话以及精致的3D效果等。

二:使用方法:

1.首先我们需要先找到素材图片

可以找一张gif动图然后自己截图,也可以使用gif分解软件,比如:GifSplitter,将gif动图分解成一张一张的图片

2.将图片添加进drawable里

然后在drawable里面创建一个 Drawabe resource file

然后点击OK

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false"
    >
    <item android:drawable="@drawable/a1" android:duration="100"/>
    <item android:drawable="@drawable/a2" android:duration="100"/>
    <item android:drawable="@drawable/a3" android:duration="100"/>
    <item android:drawable="@drawable/a4" android:duration="100"/>
    <item android:drawable="@drawable/a5" android:duration="100"/>
    <item android:drawable="@drawable/a6" android:duration="100"/>
</animation-list>

android:oneshot = " "  //表示的是播放一次  false表示循环播放  true则表示播放一次就停止

android:drawable:=" "//里面放置图片

android:duration=” “ //图片持续播放多少时间 以毫秒值为单位

3.在布局文件里面放置一个ImageView 和 两个Button

imageview里面设置Background为我们刚刚创建的drawable resource file

然后在主函数里面

AnimationDrawable animationDrawable;
animationDrawable = (AnimationDrawable) image.getBackground();

然后再调用:

animationDrawable.start();
animationDrawable.stop();

即可。

三:可能会遇到的问题:

我们添加图片的时候,要把

Android调为Project

然后再将图片添加到drawable里面,这样可以避免出现空指针异常。

如果我们直接在Android里面就添加图片,图片可能添加到了drawable-v24目录下,系统在drawable里面找不到,所以就会报空指针。

猜你喜欢

转载自blog.csdn.net/ykx_1448488568/article/details/82251172
今日推荐