Android 帧动画 FrameAnimation 简单DEMO

概念:

逐帧动画是一种常见的动画形式(Frame By Frame),其原理是在“连续的关键帧”中分解动画动作,也就是在时间轴的每帧上逐帧绘制不同的内容,使其连续播放而成动画。 因为逐帧动画的帧序列内容不一样,不但给制作增加了负担而且最终输出的文件量也很大,但它的优势也很明显:逐帧动画具有非常大的灵活性,几乎可以表现任何想表现的内容,而它类似与电影的播放模式,很适合于表演细腻的动画。例如:人物或动物急剧转身、 头发及衣服的飘动、走路、说话以及精致的3D效果等等。

步骤

  • 将图片放在res/drawable 目录下
  • 定义动画文件 如:animation.xml
  • 为指定控件绑定动画效果
  • animationDrawable.start()开启动画效果

代码

  1. 动画文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <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"/>
</animation-list>

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();
    }
}

效果图:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值