- 浏览: 47670 次
- 性别:
- 来自: 西安
最新评论
frame-by-frame animation 是一个展示一连串图片的简单的动画
实现frame-by-frame animation 的步骤
A将一连串图片存放在drawable文件夹中
B define the list of frames to be animated. the name of the file is aframe_animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/circle1" android:duration="50" />
<item android:drawable="@drawable/circle2" android:duration="50" />
<item android:drawable="@drawable/circle3" android:duration="50" />
</animation-list>
上面这个xml的作用时将这三张图片一次放映,时间间隔是50mill second
create XML Layout File for the Frame Animation Example
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id = "@+id/textViewId1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Debuge Scrath pad"
/>
<Button
android:id = "@+id/startButtonId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="start animation"/>
<ImageView
android:id = "@+id/animationImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
the main Activity
package hust.ophoneclub.FrameAnimation;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FrameAnimation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupButton();
}
/**
*
*/
private void setupButton() {
Button btn =(Button)findViewById(R.id.startButtonId);
btn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
startAnimate();
}
});
}
private void startAnimate() {
ImageView imageView = setBackgroundOfImageView();
animate(imageView);
}
/**
* @param imageView
*/
private void animate(ImageView imageView) {
AnimationDrawable frameAnimation =
(AnimationDrawable)imageView.getBackground();
if(frameAnimation.isRunning()){
frameAnimation.stop();
}else{
frameAnimation.stop();
frameAnimation.start();
}
}
private ImageView setBackgroundOfImageView() {
ImageView imageView =(ImageView)findViewById(R.id.animationImage);
imageView.setVisibility(ImageView.VISIBLE);
imageView.setBackgroundResource(R.drawable.frame_animation);
return imageView;
}
}
说明:frameAnimation是作为main.xml中的background
imageView.setBackgroundResource(R.drawable.frame_animation);
这句代码的作用是将定义frame Animation 的 xml rescourse 文件转化为一个AnimationDrwable 对象
加到imageView的背景上 所以我们要取得这个对象来进行相关的操作
AnimationDrawable frameAnimation =
(AnimationDrawable)imageView.getBackground();
这句代码就取得了这个对象;
最后的效果是这样的
发表评论
-
Android Intent and Intent Filter (转)
2011-03-10 22:47 1460Android Intent and Intent ... -
Intent详解
2011-03-03 14:18 1142在应用中,我们可以以两种形式来使用Intent: 直接I ... -
Intent间传送数据一般有两种常用方法
2011-01-24 14:50 1307Intent间传送数据一般有两种常用的办法: 1.extra ... -
android RelativeLayout 详解
2011-01-01 09:46 1580<?xml version="1.0" ... -
How to Use Android Downloads Provider
2010-12-20 21:41 1332本文转载自 http://blog.lytsing.or ... -
android 开发中的一些小知识点
2010-12-17 09:49 10001 关于onPause(): onPause ... -
content provider 深入解析
2010-12-15 22:04 1099Content providers are on ... -
Service的高级应用
2010-12-12 20:48 1356下面是android Service的高级应用的一个例子,主要 ... -
TabActivity
2010-12-12 19:09 1772下面是一个使用android tabactivity 的例子 ... -
android 测试初探(android test)
2010-12-07 15:00 8015android Testing and Instrumenta ... -
Localization of android
2010-12-05 21:51 0android 会在不同地域的不同机器上运行。为了是应用能够 ... -
android高效编程之使用本地变量
2010-12-05 14:26 976hava a look at the following co ... -
在不同的Activity中传递对象的方法
2010-12-02 10:20 2012下面我们将要实现的功 ... -
Cursor与Adapter
2010-11-21 08:34 1228来自: http://hi.baidu.com/lfcaoli ... -
Working with Context Menus
2010-11-15 23:36 861... -
Handler的理解
2010-11-14 20:58 837A Handler allows you to sen ... -
android开发问题解决日志
2010-11-14 18:33 18801.、android中R文件消失的处理方式 ... -
android 中对SDCard 的操作
2010-11-11 14:14 1637对于像视频这样的大文件,我们可以把它存放在SDCard。 SD ... -
ViewAnimation
2010-11-05 12:46 1040view animation 的实现 Understandi ... -
android高效的编写高效代码
2010-10-17 19:13 788本文来源于: 从此学习网 原文: http://www.con ...
相关推荐
本教程将基于提供的"安卓帧动画FrameAnimation例子"来深入探讨帧动画的使用。 帧动画是Android视图动画系统的一部分,适用于那些不需要复杂的交互或物理模拟的简单动画场景。它主要由`AnimationDrawable`类来实现,...
帧动画(Frame Animation)是Android系统提供的一种简单且直观的动画实现方式,它通过连续播放一系列静态图片来创建动态效果,类似于我们小时候看的动画书。在Android开发中,帧动画通常用于实现简单的动效,比如...
AnimationDrawable frameAnimation = (AnimationDrawable) getResources().getDrawable(R.anim.frame_animation); imageView.setBackground(frameAnimation); frameAnimation.start(); ``` **控制动画行为** 除了...
首先,帧动画是基于Android的`Animation`类家族中的`FrameAnimation`。它通过在一个资源文件夹(通常是`res/anim`)中定义一个XML文件来实现,该文件列出了要连续显示的图像资源ID和它们的持续时间。在...
在Android开发中,帧动画(Frame Animation)是一种常见的动画效果,它通过连续播放一系列静态图像来创建动态效果,类似于传统的电影胶片。本教程将通过一个小型的Demo来讲解如何在Android应用中实现帧动画。 首先...
"Animation_Frame_Android_XML"这个主题主要关注如何使用XML来定义逐帧动画,特别是实现WIFI图标的变化效果。逐帧动画是一种常见的动画形式,它通过连续播放一系列静态图像来创造动态视觉效果,类似于传统的电影制作...
这个简单的例子展示了如何在WPF中使用`Frame`的`Navigate`方法和`NavigationUIVisibility`属性实现无UI导航。对于初学者,这是一个很好的起点,可以帮助理解WPF中页面导航的基本工作原理。通过深入学习和实践,你...
在这个例子中,`@drawable/frame1`和`@drawable/frame2`是帧图片的资源引用,`android:duration`表示每帧显示的时间,单位是毫秒。 2. 在布局文件中使用 在你的布局XML文件中,添加一个ImageView并设置其背景为上述...
Android提供了两种基础的动画类型:`Tween Animation`(补间动画)和`Frame Animation`(帧动画)。 - **Tween Animation**:用于改变View的位置、大小、透明度等属性,通过指定起始值和结束值,在一定时间内平滑...
在这个例子中,`<animation-list>`是必需的根元素,`android:oneshot`属性控制动画是否只播放一次(如果设为`true`)还是无限循环(如果设为`false`)。`<item>`元素代表每一帧,`android:drawable`属性指定该帧对应...
`Animation`有两种主要类型:补间动画(Tween Animation)和帧动画(Frame Animation)。补间动画主要用于改变对象的位置、大小、旋转等属性,而帧动画则是播放一系列静态图像来创建连续的视觉效果。 二、自定义...
在`AnimationDemo`中,可能包含了使用`Animation`类、`AnimationSet`、`AlphaAnimation`、`ScaleAnimation`、`TranslateAnimation`和`RotateAnimation`的例子。 2. **属性动画(Property Animation)**:自API Level ...
bower install animationframe 或从此存储库下载 js 文件 ##例子: $(".dom").animationFrame({ "duration": 1000, "easing": "linear|ease|cubicBezier", "from": { "left": "0px", "top": "0px", ...
在这个例子中,我们有三个帧,分别是frame1、frame2和frame3,每个帧的持续时间为100毫秒。 设置ImageView显示动画: 在布局文件中,我们可以将ImageView的src属性设置为我们的`animation_list`资源: ```xml ...
"ios应用源码之恩,我也发个core animation例子……nanolife for iphone nanolife"这个项目很可能是为了展示如何在实际应用中使用Core Animation。 首先,我们来理解一下Core Animation的基本概念。Core Animation...
AnimationDrawable frameAnimation = (AnimationDrawable) ContextCompat.getDrawable(this, R.drawable.your_animation_xml); imageView.setImageDrawable(frameAnimation); // 启动动画 frameAnimation.start(); ...
这个小例子将基于Android SDK提供的帧动画功能,适用于2D游戏、动态图标或其他视觉效果的实现。 首先,我们要理解Android中的逐帧动画。在Android中,帧动画(Frame Animation)是一种简单易用的动画形式,它通过...
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.start(); ``` **二、Tween Animation(补间动画)** 补间动画则更加灵活,可以实现物体的平移、旋转、缩放和...
在Android开发中,帧动画(Frame Animation)是一种常见的动画效果,它通过连续播放一系列静态图像来创造出动态的视觉效果,类似于传统的电影制作原理。在这个"android 简单的帧动画例子"中,我们将探讨如何在...
在这个例子中,`frame1`、`frame2`和`frame3`是不同帧的图片资源,`duration`属性定义了每帧持续的时间,单位为毫秒。持续时间越短,动画速度越快。 接下来,我们需要在代码中设置并启动这个动画。首先,在布局文件...