android 100逐帧动画资源,Android 逐帧动画创建实例详解

Android 逐帧动画创建实例详解

发布时间:2020-10-02 05:49:25

来源:脚本之家

阅读:99

作者:lqh

Android 逐帧动画创建实例详解

前言:

我们看早期电影的时候,电影通常是一张一张播放,用我们现在专有名词来说,就是一帧帧来,安卓同样有这样动画效果的编排形式。

那么我们先定义逐帧动画xml文件

xmlns:android="http://schemas.android.com/apk/res/android"

android:oneshot="true">

android:drawable="@drawable/pic1"

android:duration="200" />

android:drawable="@drawable/pic2"

android:duration="200" />

android:drawable="@drawable/pic3"

android:duration="200" />

android:drawable="@drawable/pic4"

android:duration="200" />

android:drawable="@drawable/pic5"

android:duration="200" />

android:drawable="@drawable/pic6"

android:duration="200" />

android:drawable="@drawable/pic7"

android:duration="200" />

android:drawable="@drawable/pic8"

android:duration="200" />

android:drawable="@drawable/pic8"

android:duration="200" />

main.xml

android:id="@+id/pic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_marginLeft="98dp"

android:layout_marginTop="69dp"

/>

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_marginBottom="54dp"

android:layout_marginLeft="98dp"

android:onClick="startMovie"

android:text="开始播放电影" />

Activiy代码:

public class MyAnimationDemo extends Activity {

private AnimationDrawable draw=null;

private ImageView image;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_my_animation_demo);

image=(ImageView)super.findViewById(R.id.pic);

}

public void startMovie(View v){

image.setBackgroundResource(R.anim.oldvideo);//第一步,设置图片资源

draw=(AnimationDrawable)image.getBackground();//取得图片背景的Drawable

draw.setOneShot(false);//动画执行次数

draw.start();//开始动画

}

}

这里我们看到,

第一步,设置图片背景资源

第二步,设置得到图片背景的draw

第三步,设置draw参数,并start()

实现效果如下,间隔0.2秒即换图,实现老电影动画效果

2e184fbf31d102dfa2ba6564c1003a87.png

ba5ef84cfb453fbe32655337bf0d942a.png

d3634272b49a51f455e9645ce364e487.png

以上就是Android 逐帧动画的实例详解,如有疑问请留言或到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 平台上使用 Animator 创建逐帧动画可以通过以下步骤实现: 1. 首先,在 res/drawable 目录下创建一个 XML 文件来定义您的动画序列,例如: ```xml <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/frame1" android:duration="100"/> <item android:drawable="@drawable/frame2" android:duration="100"/> <item android:drawable="@drawable/frame3" android:duration="100"/> <item android:drawable="@drawable/frame4" android:duration="100"/> <item android:drawable="@drawable/frame5" android:duration="100"/> </animation-list> ``` 上述代码定义了一个包含 5 动画动画序列,每一的持续时间为 100ms。 2. 在您的 Activity 中,使用以下代码来加载动画并将其应用到 ImageView 上: ```java ImageView imageView = findViewById(R.id.imageView); AnimationDrawable animation = (AnimationDrawable) getResources().getDrawable(R.drawable.my_animation); imageView.setImageDrawable(animation); animation.start(); ``` 上述代码中,我们首先通过 findViewById 方法获取了 ImageView 控件的实例,然后通过 getResources().getDrawable 方法加载了我们在第一步中定义的动画序列,并将其设置为 ImageView 的背景。最后,我们调用了动画的 start 方法来启动动画。 以上就是使用 Animator 创建逐帧动画的基本步骤。您可以根据自己的需要对动画序列进行修改和扩展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值