Android Animation学习(六) View Animation介绍

View Animation

  View animation系统可以用来执行View上的Tween animationFrame animation

  Tween animation可以在View对象上执行一系列的简单变换,比如位置、尺寸、旋转、透明度等。

  animation package 包中包含了tween animation所有的类。

  一系列的动画命令定义了一个完整的tween animation,可以用代码定义也可以用XML资源文件定义。

XML资源文件

  XML资源文件的使用可以见:Animation Resources

  XML文件放在项目的res/anim/目录下。文件必须有一个唯一的根节点。

  这个根节点可以是:<alpha>, <scale>, <translate>, <rotate>, interpolator element, 或者是<set>。

  默认情况下,所有的动画都是并行进行的,要想使得它们顺寻发生,你必须指定startOffset属性。

  有一些值,可以指定是相对于View本身还是相对于父类容器的。

  比如pivotX,要表示相对于自身的50%,要用50%;要表示相对于父类容器的50%,则直接写50

使用例子

  XML文件存储为:res/anim/hyperspace_jump.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
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/accelerate_interpolator"
android:startOffset="700">
<scale
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="0.6"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
</set>
</set>

  在代码中把这个动画应用于一个ImageView:

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

  除了调用 startAnimation() ,另一种处理方式是通过Animation.setStartTime()方法定义一个开始时间,然后通过View.setAnimation()方法把这个动画赋给控件即可。

View Animation和Property Animation

  View Animation是API Level 1就引入的。

  View Animation在包android.view.animation中。

  动画类叫Animation

  Property Animation是API Level 11引入的,即Android 3.0才开始有Property Animation相关的API。

  Property Animation API在包 android.animation中。

  动画相关类叫Animator

参考资料

  API Guides:View Animation

  http://developer.android.com/guide/topics/graphics/view-animation.html

  Tween animation的包:

  http://developer.android.com/reference/android/view/animation/package-summary.html

  Animation类:

  http://developer.android.com/reference/android/view/animation/Animation.html

  Animation Resources

  http://developer.android.com/guide/topics/resources/animation-resource.html

Android Animation学习(六) View Animation介绍的更多相关文章

  1. 【Android界面实现】View Animation 使用介绍

        转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992     我们能够使用view animation 动画系统来给View控件加入tween动画(下称& ...

  2. 浅谈Android样式开发之View Animation (视图动画)

    引言 一个用户体验良好的App肯定少不了动画效果.Android为我们提供了2种动画框架,分别是视图动画(View Animation)和属性动画(Property Animation).视图动画比较 ...

  3. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  4. android开发学习 ------- 自定义View 圆 ,其点击事件 及 确定当前view的层级关系

    我需要实现下面的效果:   参考文章:https://blog.csdn.net/halaoda/article/details/78177069 涉及的View事件分发机制 https://www. ...

  5. Android多媒体学习六:利用Service实现背景音乐的播放

    Android同意我们使用Service组件来完毕后台任务.这些任务的同意不会影响到用户其它的交互. 1.Activity类 [java] view plaincopy package demo.ca ...

  6. Android 虚拟机学习总结Dalvik虚拟机介绍

    1.Dalvik虚拟机与Java虚拟机的最显著差别是它们分别具有不同的类文件格式以及指令集.Dalvik虚拟机使用的是dex(Dalvik Executable)格式的类文件,而Java虚拟机使用的是 ...

  7. Android开发学习——自定义View

    转载自: http://blog.csdn.net/xmxkf/article/details/51454685 本文出自:[openXu的博客]

  8. Android JNI 学习(六):Object Operations Api

    一.AllocObject jobjectAllocObject(JNIEnv *env, jclass clazz); 分配新 Java 对象而不调用该对象的任何构造函数.返回该对象的引用. cla ...

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

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

随机推荐

  1. Android Permission中英对照

    android.permission.ACCESS_CHECKIN_PROPERTIESAllows read/write access to the "properties" t ...

  2. 关于HttpHandler的相关知识总结

    一.关于IHttpHandler.IsReusable 很多人不明白,这哥们到底干嘛的,估计是微软最初的一个想法--让一个对象可以一直不断地被重复使用 ,但这个想法不成熟,会带来很多隐藏问题,一个对象 ...

  3. 使用Python将HTML转成PDF

    主要使用的是wkhtmltopdf的Python封装--pdfkit 安装 1. Install python-pdfkit: $ pip install pdfkit 2. Install wkht ...

  4. 兼容各浏览器的iframe - onlaod事件

    上次工作中,在使用 Iframe+FormSubmit进行无刷新提交时,如果后台返回的数据有延迟,或者浏览器对Iframe内容的更改过慢的话,会遇到onload响应在Iframe内容改变之前触发,这也 ...

  5. 15天玩转redis —— 第五篇 集合对象类型

    这篇我们来看看Redis五大类型中的第四大类型:“集合类型”,集合类型还是蛮有意思的,第一个是因为它算是只使用key的Dictionary简易版, 这样说来的话,它就比Dictionary节省很多内存 ...

  6. VS使用WinRAR软件以命令行方式打包软件至一个exe

    由于项目需要,需要将一个绿色版软件(即无需在C盘写入文件)发给客户使用,要求是只有一个exe文件,双击即可执行.​ 网上说WinRAR软件创建自解压文件可以实现,链接http://blog.csdn. ...

  7. JAVA中的输入方法

    输入整数(int)类型 导入包 import java.io.*; 输入语句 BufferedReader myIn=new BufferedReader(new inputStreamReader( ...

  8. Servlet—简单的管理系统

    网站的框架 网站的框架采用MV模式,即Model(模型).View(视图).框架将界面层和模型层进行分离,结构更清晰,更加方便管理代码. 其中上图框架中的修改和删除功能完成而添加查询模块没有编写 实现 ...

  9. Lua-面向对象中函数使用时冒号(:)和点(.)的区别

    先来看一段简单的代码: local Animal = {} function Animal:Eat( food ) print("Animal:Eat", self, food) ...

  10. bootstrap的下拉框在firefox界面不友好的处理

    http://output.jsbin.com/titaki 以上这个链接在firefix浏览器打开就会发现里面有个小容器,而且下拉按钮样式跟不友好 上谷歌查了一下 1.小容器可以利用select:p ...