广告
返回顶部
首页 > 资讯 > 移动开发 >Android编程之简单逐帧动画Frame的实现方法
  • 921
分享到

Android编程之简单逐帧动画Frame的实现方法

frame程之方法Android 2022-06-06 09:06:56 921人浏览 泡泡鱼
摘要

本文实例讲述了Android编程之简单逐帧动画Frame的实现方法。分享给大家供大家参考,具体如下: 1、逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影

本文实例讲述了Android编程之简单逐帧动画Frame的实现方法。分享给大家供大家参考,具体如下:

1、逐帧动画

即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影。

2、实现步骤:

① 在工程里面导入要播放的图片。此简单例子中为start_icon1,2,3.

② 在工程res文件目录下新建一个anim文件夹,在里面新建一个start_animation.xml格式文件,此文件用来定义动画播放图片的顺序及每一张图片显示停留时间。

代码如下:


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="Http://schemas.android.com/apk/res/android"
  android:oneshot="false">
  <item android:drawable="@drawable/start_icon1" android:duration="1000" />
  <item android:drawable="@drawable/start_icon2" android:duration="500" />
  <item android:drawable="@drawable/start_icon3" android:duration="600" />
</animation-list>

注:此蓝色部分依次显示的图片,存放在drawable-mdpi文件下,一般1秒钟播放24张图片(帧)就感觉播放流畅了,即duration为40左右,默认单位为毫秒。

3、布局文件:

布局文件中添加一ImageView控件,用来播放动画图片。具体布局如下:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="开始" />
  <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_gravity="center"
    android:text="结束" />
  <ImageView
    android:id="@+id/image"
    android:background="@anim/start_animation"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout>

4、代码部分:


public class TestActivity extends Activity
{
AnimationDrawable anim;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.start_screen);
ImageView image = (ImageView) findViewById(R.id.image);
// image.setBackgroundResource(R.anim.start_animation);
anim = (AnimationDrawable) image.getBackground();
Button start = (Button) findViewById(R.id.button1);
Button stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.start();
}
});
stop.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.stop();
}
});
}
}

注:第三步中的android:background="@anim/start_animation"和第四步中的 image.setBackgroundResource(R.anim.start_animation);只要选择一个就可以,两个都写显得累赘,主要功能是指定播放的资源图片。

小结:这种应用在实际应用中应该不会用到,对于初学着来说,拿着玩下还是蛮有意思的,不仅增强了对Android学习的兴趣,同时也能加深对制造电影的一些了解

希望本文所述对大家Android程序设计有所帮助。

您可能感兴趣的文章:Android 帧动画的实例详解Android 逐帧动画创建实例详解Android之仿美团加载数据帧动画Android逐帧动画实现代码Android 使用帧动画内存溢出解决方案Android帧动画、补间动画、属性动画用法详解Android 动画(View动画,帧动画,属性动画)详细介绍Android动画之逐帧动画(Frame Animation)基础学习Android动画之逐帧动画(Frame Animation)实例详解Android利用animation-list实现帧动画


--结束END--

本文标题: Android编程之简单逐帧动画Frame的实现方法

本文链接: https://www.lsjlt.com/news/26148.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作