Android 动画的基本原理
来源:互联网 发布:c语言编写俄罗斯方块 编辑:程序博客网 时间:2024/06/05 05:07
An animation resource can define one of two types of animations:
Property Animation
Creates an animation by modifying an object's property values over a set period of time with an Animator.
View Animation
There are two types of animations that you can do with the view animation framework:
Tween animation: Creates an animation by performing a series of transformations on a single image with an AnimationFrame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable.
阅读官方源码,我们知道动画分为属性动画和视图动画两种类型,而视图动画又分为:
补间动画:创建一个动画通过执行一系列的转换在一个图像和动画帧动画:或者创建一个动画通过显示一个图像序列为了AnimationDrawable。
一:Property Animation 属性动画
语法:
文件必须有一个根元素:,< objectAnimator >或< valueAnimator >。你可以动画元素分组在元素,包括其他元素。
1,<set>
是包含其他动画元素的容器(< objectAnimator >、< valueAnimator >或<设置>元素)。代表一个动画集合。
属 性:1.1:android:ordering sequentially:表示按顺序按顺序播放动画在这个集合中 together(default) : (默认)一起在这组同时播放动画。
2,<objectAnimator>
的一个特定对象的属性在一个特定的时间。代表一个ObjectAnimator
属 性:2.1:android:propertyName string,必需的。对象的属性动画,通过其名称引用。例如您可以指定“α”或“写成backgroundColor”视图对象。objectAnimator元素不暴露目标属性, 然而,所以你不能在XML声明中设置对象动画。你必须抬高你的动画XML资源通过调用loadAnimator()和调用setTarget()来设置目标对象,其中包含这个属性。2.2:android:valueTo float,int或颜色。必需的。在动画属性的值。颜色表示为六位十六进制数字(例如,# 333333)。2.3:android:valueFrom float,int或颜色。动画的属性的值开始。如果不指定,动画开始获得的价值属性的get方法。颜色表示为六位十六进制数字(例如,# 333333)。2.4:android:duration int,动画的时间以毫秒为单位。300毫秒是默认的2.5:android:startOffset int。动画的毫秒延迟之后开始()2.6:android:repeatCount int。多少次重复动画。设置为“-1”无限重复或一个正整数。例如,值为“1”意味着动画是动画的初始运行后重复一次,所以动画共有两次。 默认值为“0”,这意味着没有重复。2.7:android:repeatMode int。动画表现当它达到动画的结束。android:repeatCount必须设置为一个正整数或“-1”这个属性产生影响。设置为“反向”动画的反方向与每个迭代或“重复”的动画循环每次从一开始。2.8:android:valueType 没有指定这个属性值是一个颜色。动画框架自动处理颜色值2.9:android:startOffset intType: 指定动画的值是integer floatType(default): 指定动画的值是float
在代码中添加动画
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext, R.anim.property_animator);set.setTarget(myObject);set.start();
二:View Animation视图动画框架支持渐变和逐帧动画,它都可以在XML声明。以下部分描述如何使用这两种方法
1,Tween animation 补间动画中定义XML执行转换如旋转,褪色,移动,拉伸图形。
语法:
文件必须有一个根元素:,< objectAnimator >或< valueAnimator >。你可以动画元素分组在元素,包括其他元素。<set>
是包含其他动画元素的容器(< objectAnimator >、< valueAnimator >或<设置>元素)。代表一个动画集合。
2,<set>
是包含其他动画元素的容器(< objectAnimator >、< valueAnimator >或<设置>元素)。代表一个动画集合。
属性android:interpolator 插入资源。一个在动画插入应用。的值必须是一个引用资源指定一个插入(不是一个插入类名)。有默认插入可用资源的平台或您可以创建自己的插入器资源。请参阅下面的讨论更多关于插入。android:shareInterpolator 布尔类型。“真正的”如果你想共享相同的插入器在所有子元素。
2.1,alpha 淡入淡出 淡入或淡出动画。表示一个AlphaAnimation
android:fromAlpha Float. Starting opacity offset, where 0.0 is transparent and 1.0 is opaque. android:toAlpha Float. Ending opacity offset, where 0.0 is transparent and 1.0 is opaque.For more attributes supported by <alpha>, see the Animation class reference (of which, all XML attributes are inherrited by this element).
2.2,scale缩放一个调整动画。您可以指定图像的中心点,它向外生长(或进口)通过指定pivotX pivotY。例如,如果这些值0,0(左上角),所有增长将向下和向右。代表一个ScaleAnimation。
android:fromXScale Float. Starting X size offset, where 1.0 is no change. android:toXScale Float. Ending X size offset, where 1.0 is no change. android:fromYScale Float. Starting Y size offset, where 1.0 is no change. android:toYScale Float. Ending Y size offset, where 1.0 is no change. android:pivotX Float. The X coordinate to remain fixed when the object is scaled. android:pivotY Float. The Y coordinate to remain fixed when the object is scaled.
2.3,translate平移 一个垂直和/或水平运动。支持以下属性有下列三种格式:价值观与“%”从-100年到100年结束,表明比例相对于本身,价值从-100年到100年结束在“% p”,指示一个百分比相对于其父;没有后缀的浮动值,指示一个绝对的价值。代表一个TranslateAnimation。
android:fromXDelta Float or percentage. Starting X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p"). android:toXDelta Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p"). android:fromYDelta Float or percentage. Starting Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p"). android:toYDelta Float or percentage. Ending Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p").
2.4,rotate一个旋转动画。代表一个RotateAnimation
android:fromDegrees Float. Starting angular position, in degrees. android:toDegrees Float. Ending angular position, in degrees. android:pivotX Float or percentage. The X coordinate of the center of rotation. Expressed either: in pixels relative to the object's left edge (such as "5"), in percentage relative to the object's left edge (such as "5%"), or in percentage relative to the parent container's left edge (such as "5%p"). android:pivotY Float or percentage. The Y coordinate of the center of rotation. Expressed either: in pixels relative to the object's top edge (such as "5"), in percentage relative to the object's top edge (such as "5%"), or in percentage relative to the parent container's top edge (such as "5%p").
事例:在Rnim文件夹下新建文件hyperspace_jump.xml
引用
ImageView image = (ImageView) findViewById(R.id.image);Animation hyperspaceJump=AnimationUtils.loadAnimation(this,R.anim.hyperspace_jump);image.startAnimation(hyperspaceJump);
三,Frame animation XML中定义的动画显示一个图像序列(如电影)。
1,语法
1.1 <animation-list> 这一定是根元素。包含一个或多个< item >元素。 android:oneshot 布尔。“真正的”如果你想执行一次动画;“false”循环动画。1.2 <item> 单帧动画。必须是一个孩子的< animation-list >元素。 android:drawable drawable资源。用于绘制的帧。 android:duration 整数。显示帧持续时间,以毫秒为单位。
事例:在Rnim文件夹下新建rocket_thrust.xml
引用
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);rocketImage.setBackgroundResource(R.drawable.rocket_thrust);rocketAnimation = (AnimationDrawable) rocketImage.getBackground();rocketAnimation.start();
到此,动画讲解就结束了,借此自我总结一下,也希望能帮到用到者
- Android 动画的基本原理
- Android 动画框架的基本原理
- Animation(动画的基本原理)
- 动画基本原理
- Android应用的基本原理
- Android App的基本原理
- Android AsyncTask的实现基本原理
- JavaScript动画基本原理
- JavaScript动画实现基本原理
- 深度探索Android应用程序的基本原理
- android 电池(一):锂电池的基本原理
- android API 之应用程序的基本原理
- Android中ContentProvider的基本原理学习总结
- Android中自定义Adapter的基本原理
- Android API 学习日记----《应用程序的基本原理》
- Android中AudioFlinger的基本原理介绍
- Android中自定义Adapter的基本原理
- android注解的基本原理和使用
- 第三方SDK:JPush:Android Studio
- Nginx初探
- windows下安装mysql5.7及以上版本注意事项
- 【Linux系统编程应用】Linux音频编程接口
- 剑指offer面试题19:二叉树的镜像
- Android 动画的基本原理
- 湖南省第十二届大学生计算机程序设计竞赛 A 2016
- select into from 和 insert into select 的用法和区别
- 大数相加
- 在html中使用javascript注意事项
- Android——Tomcat版本更新下载+头像照片上传到Tomcat
- office 2010 Word,Excel的功能区突然消失了
- 消息队列入门(二)消息队列的规范和开源实现
- [CSU 1803(湖南省赛16)] 有向无环图 (DAG+公式化简)