【专题】Android Frame动画

Android Frame动画是指帧动画,如果你了解flash相关,就知道帧动画是把一帧帧的对象组成起来,然后一帧一帧的播放,跟电影播放差不多。

什么情况下会使用帧动画呢?

下面就来个实际的项目例子例子,

本来想添加个实际项目里的GIF动画的,结果发现没有软件录屏幕。

Android 帧动画 可以通过两种方式来设置加载动画,一种是直接配置xml文件的形式,第二种是直接通过过代码的形式。

下面来看第一种,

创建动画xml文件

路径: /res/anim/shutter.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/shutter0" android:duration="100" />   
<item android:drawable="@drawable/shutter1" android:duration="100" />   
<item android:drawable="@drawable/shutter2" android:duration="100" />    
</animation-list>

在Activity中使用

ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.anim.shutter;
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();    // 开始动画
frameAnimation.stop();    // 停止动画
frameAnimation.setOneShot(false);   // 设置不循环播放
frameAnimation.isRunning();            // 是否在播放动画

再来看第二种

在Activity中使用

private int[] frame = new int[] {R.drawable.shutter0, R.drawable.shutter1, R.drawable.shutter2};
AnimationDrawable frameAnimation = new AnimationDrawable()
for (int id : frame) {
    Drawable frame =  activity.getResources().getDrawable(id);   frameAnimation.addFrame(frame, 1000);
}frameAnimation.setOneShot(false);
frameAnimation.start();    // 开始动画
frameAnimation.stop();    // 停止动画
frameAnimation.setOneShot(false);   // 设置不循环播放
frameAnimation.isRunning();            // 是否在播放动画



转载于:https://my.oschina.net/oldmou/blog/228780

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值