Android 帧动画 FrameAnimation 简单DEMO
- 概念
- 步骤
- 代码
- 效果图
概念:
逐帧动画是一种常见的动画形式(Frame By Frame),其原理是在“连续的关键帧”中分解动画动作,也就是在时间轴的每帧上逐帧绘制不同的内容,使其连续播放而成动画。 因为逐帧动画的帧序列内容不一样,不但给制作增加了负担而且最终输出的文件量也很大,但它的优势也很明显:逐帧动画具有非常大的灵活性,几乎可以表现任何想表现的内容,而它类似与电影的播放模式,很适合于表演细腻的动画。例如:人物或动物急剧转身、 头发及衣服的飘动、走路、说话以及精致的3D效果等等。
步骤
- 将图片放在res/drawable 目录下
- 定义动画文件 如:
animation.xml
- 为指定控件绑定动画效果
animationDrawable.start()
开启动画效果
代码
动画文件
<?xml version=”1.0” encoding=”utf-8”?>
<item android:drawable="@drawable/a1" android:duration="200"/>
<item android:drawable="@drawable/a2" android:duration="200"/>
<item android:drawable="@drawable/a3" android:duration="200"/>
<item android:drawable="@drawable/a4" android:duration="200"/>
<item android:drawable="@drawable/a5" android:duration="200"/>
<item android:drawable="@drawable/a6" android:duration="200"/>
<item android:drawable="@drawable/a7" android:duration="200"/>
<item android:drawable="@drawable/a8" android:duration="200"/>
<item android:drawable="@drawable/a9" android:duration="200"/>
<item android:drawable="@drawable/a10" android:duration="200"/>
<item android:drawable="@drawable/a11" android:duration="200"/>
<item android:drawable="@drawable/a12" android:duration="200"/>
<item android:drawable="@drawable/a13" android:duration="200"/>
<item android:drawable="@drawable/a14" android:duration="200"/>
<item android:drawable="@drawable/a15" android:duration="200"/>
<item android:drawable="@drawable/a16" android:duration="200"/>
2 java代码
package cn.zsp.frameanimation;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.iv);
//第一种:加载布局
mImageView.setBackgroundResource(R.drawable.animation);
//拿到imageview 的帧动画
AnimationDrawable animationDrawable= (AnimationDrawable) mImageView.getBackground();
//添加一个动画 帧
animationDrawable.addFrame(getResources().getDrawable(R.drawable.g1),200);
//开始帧动画
animationDrawable.start();
}
}
还没有评论,来说两句吧...