前一章中总结了android animation中property animation的知识和用法,这一章总结View animation和Drawable animation的有关知识:

View animation就是网上常讲的tweened animation,android.view.animation包包括了tweened animation用到的所有的类,Demo请看例子,地址:http://download.csdn.net/detail/u010966622/5664895

不论是xml的动画还是android code编写的动画,都可以定义一个连续播放的动画.建议用xml文件动画,因为它更容易完成,更容易重运用,更容易修改.    xml动画文件放在res/anim文件夹当中.这个文件必须有一个跟元素(<alpha/scale/translate/rotateinterpolator element/set>),默认所有的动画是同时进行的,为了让他们一个接一个进行,你可以定义startoffset属性来控制,就像下边的代码一样:

<set android:shareInterpolator="false">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700" />
<set android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="0.6"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400"
android:fillBefore="false" />
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="400" />
</set>
</set>

屏幕坐标为左上角是(0,0),往下往右依次增加. 有一些值,比如pivoitX可以被赋值为相对值,比如50%,意思是相对于自己的50%.50意思是想对于父控件的50%. 也可以定义Interpolator,就是速度插入器,在上篇property animation中有详细介绍.

ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
spaceshipImage.startAnimation(hyperspaceJumpAnimation);

也可以不调用startAnimation函数,直接定义:animation.setStarttime(),当到达那个时间点后,此动画会自动进行.

    Drawable Animation 可以帮助你将一个一个Drawable resources一个接一个的播放出来,就像传统的动画一样.AnimationDrawable类是Drawable animation的基础.

Drawable Animation 虽然是动画,但是还是由Drawable resources组合而成的,所以其xml文件一般放在res/drawable中,其xml文件是由<animation-list>元素组成其根节点,<item>组成其框架,下面是例子:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
android:oneshot="true"表示其只进行一次播放,然后停在最后一个drawable上,当oneshot被设为false的时候,它将会一直循环播放.下边是一个例子,当屏幕被触摸时,会将此动画加载在这个imageview上并且运行
AnimationDrawable rocketAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rocketAnimation.start();
return true;
}
return super.onTouchEvent(event);
}

在上面的例子中,我们可以看到,方法start()的调用不能在onCreate()方法中调用,因为要动画的view还未被添加到窗口当中,如果想立刻运行动画的话,你可以重写onWindowfocuschanged()方法,当此activity被放到最前端的时候自动执行.

Android animation学习笔记之view/drawable animation的更多相关文章

  1. Android动画学习笔记-Android Animation

    Android动画学习笔记-Android Animation   3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...

  2. Android Animation学习(一) Property Animation原理介绍和API简介

    Android Animation学习(一) Property Animation介绍 Android Animation Android framework提供了两种动画系统: property a ...

  3. android拾遗——Android 动画学习笔记

    3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...

  4. Android:日常学习笔记(8)———探究UI开发(5)

    Android:日常学习笔记(8)———探究UI开发(5) ListView控件的使用 ListView概述 A view that shows items in a vertically scrol ...

  5. Android:日常学习笔记(7)———探究UI开发(4)

    Android:日常学习笔记(7)———探究UI开发(4) UI概述  View 和 ViewGrou Android 应用中的所有用户界面元素都是使用 View 和 ViewGroup 对象构建而成 ...

  6. Android:日常学习笔记(7)———探究UI开发(1)

    Android:日常学习笔记(7)———探究UI开发(1) 常用控件的使用方法 TextView 说明:TextView是安卓中最为简单的一个控件,常用来在界面上显示一段文本信息. 代码: <T ...

  7. Android自动化学习笔记:编写MonkeyRunner脚本的几种方式

    ---------------------------------------------------------------------------------------------------- ...

  8. Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例

    ---------------------------------------------------------------------------------------------------- ...

  9. Android:日常学习笔记(8)———探究UI开发(3)

    Android:日常学习笔记(8)———探究UI开发(3) 详解四种基本布局 前言 布局定义用户界面的视觉结构,如Activity或应用小部件的 UI.您可以通过两种方式声明布局: 在 XML 中声明 ...

随机推荐

  1. hdu 4635 Strongly connected 强连通

    题目链接 给一个有向图, 问你最多可以加多少条边, 使得加完边后的图不是一个强连通图. 只做过加多少条边变成强连通的, 一下子就懵逼了 我们可以反过来想. 最后的图不是强连通, 那么我们一定可以将它分 ...

  2. (转)设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)

    转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义.靠,这货其实就是间隔,起个名字这么让 ...

  3. sim卡中电话本(ADN)的简要格式

    ADN的格式 ADN存放于sim卡下面3f00/7f10/6f3a,记录文件格式,其最小记录格式为14,最长为255(?),记录个数最大为255(?) 其后数14个字节是必有的,其前12个字节是电话号 ...

  4. 每天学点Linux:一

    软链接和硬链接: 软链接,又称符号链接,它的原理是通过一个文本文件记录真实文件在系统中的位置,然后在文件操作的时候通过该地址查找原文件然后对其操作.类似于Windows里面的快捷方式.软链接可以链接不 ...

  5. nova的 microversion 实现

    之前想写nova的policy的实现, 但是发现网上,有人写的很不错了. 但是个人认为存在一些问题. ref: http://www.cnblogs.com/shaohef/p/4527436.htm ...

  6. 达内TTS6.0课件oop_day04

  7. 解决本地访问Android文档是非常慢的问题

    不时在天上不能上网Android开发站点.要查看开发者文档,真是费劲心思,这里不再介绍访问Android开发网站developer.android.com,这里介绍怎样高速的訪问打开本地的SDK下An ...

  8. golang之interface(接口)与 reflect 机制

    一.概述 什么是interface,简单的说,interface是一组method的组合,通过interface来定义对象的一组行为: interface类型定义了一组方法,如果某个对象实现了某个接口 ...

  9. DataReader转泛型

    实体类的字段类型要和数据库一致,不然可能会出现错误. /// <summary> /// DataReader转泛型 /// </summary> /// <typepa ...

  10. 将图片文件以byte的形式从导数据库中

    byte[] FileByteArray = new byte[FileLength];  //图象文件临时储存Byte数组                 //Stream StreamObject ...