`
frand_feng
  • 浏览: 19043 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Android animation学习笔记之propery animation

 
阅读更多

    以前写博客都是用百度空间,总感觉不专业,访问量少,好友少,里边可运用的资源也少,所以昨天网上查了一下,觉得iteye社区还不错,就申请了一个iteye帐号,今天开始写博,希望大家多关注多交流,共同进步.

 

    最近一直在做中国最强音app的开发,好不容易闲了下来,觉得在做中国最强音app的时候动画方面的知识还不够扎实,所以这周腾出手来主要学习了animation和graphics方面的知识,现在先将animation方面的知识总结如下:

 

    Android框架提供了两种动画:property animation(android3.0以上会有)view animation.其中建议选property animation,因为它要更强大更高效,除了上边两种,你还可以运用drawable animation,它可以帮你导入drawable中的资源并且一个一个显示他们.

 

    ,Property animation:这种动画系统帮助你实现任何对象的动画,包括那些没有被添加到界面当中的对象.

    二,View animation:这是一种比较老的方式并且只能对Views进行使用,使用和设置起来比较容易.

    三,Drawable animation:像电影一样,一个drawable接一个进行播放.

 

What is propery animation:

 

     像谷歌原话的解释:The property animation system is a robust framework that allows you to animate almost anything.在一定的时间内,property animation可以改变一个property(a field in an object)的值,比如位置,动画持续时间,动画开始时间等,来控制一个动画.

 

     Property animation的属性包括:

 

  • Duration:动画持续的时间,系统默认为300ms.
  • Time interpolation:动画插入器,LinearInterpolator动画以均匀的速率改变
  • Repeat count and mode,动画重复次数和返回状态,restart reverse.
  • Animation sets:可以将一系列动画放入一个集合中一起进行或者一个一个进行.
  • Frame refresh delay,可以设置动画的刷新时间,系统自定义为10ms.

How property animation works:

 

     // http://developer.android.com/guide/topics/graphics/prop-animation.html#property-vs-view

 

How property animation differs from view animation

 

     view animation 只可以操作是view的对象,并且只能对view进行rotate,scale,translatealpha操作.view animation另一个不能实现的功能就是it only modified where the View was drawn, and not the actual View itself,意思是它动画的时候其实那个view实际是不在显示的位置上的.

 

     The property animation system can animate Views on the screen by changing the actual properties in the View objects. In addition, Views also automatically call the invalidate() method to refresh the screen whenever its properties are changed. The new properties in the view class that facilitate property animations are:

 

  • translationX and translationY: 相对于父控件左上角的位置
  • rotation, rotationX, and rotationY: 旋转的中心点的坐标
  • scaleX and scaleY: 缩放的中心点的坐标
  • pivotX and pivotY: 中心点的坐标
  • x and y: 距离坐标
  • alpha: 透明度,值在0到1之间

How to accompish an animation:

 

    1,Multiple ObjectAnimator objects

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();

 

     2,One ObjectAnimator

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();
 

     3,ViewPropertyAnimator

myView.animate().x(50f).y(100f);

 

 

How to Declaring Animation in XML:

 

    android开发允许你使用xml文件代替编程来运用动画,通过xml文件,你可以在多个activity中很容易的重用或重编辑你的动画.

    为了区分新的property animation 和旧的view animation,从android3.1以上,将文件名由res/anim改成res/animator, 在xml中可以设置三种动画属性:

用法如下:

<setandroid:ordering="sequentially">
    <set>
        <objectAnimator
            android:propertyName="x"
            android:duration="500"
            android:valueTo="400"
            android:valueType="intType"/>
        <objectAnimator
            android:propertyName="y"
            android:duration="500"
            android:valueTo="300"
            android:valueType="intType"/>
    </set>
    <objectAnimator
        android:propertyName="alpha"
        android:duration="500"
        android:valueTo="1f"/></set>

 

代码中:

AnimatorSetset=(AnimatorSet)AnimatorInflater.loadAnimator(myContext,
    R.anim.property_animator);set.setTarget(myObject);set.start();

 

 

Animation api overview:

 

     android.animation包中可以找到很多property animationapi,android.view.animation包中可以找到很多定义好的imterpolators.下边是propery animation system 中的组件.

 

     1,what is included in animator class

 

  •  ValueAnimator继承于animator,google 解释为The main timing engine for property animation that also computes the values for the property to be animated,就是每隔10ms计算图画的位置
  • ObjectAnimator继承于ValueAnimator,google 解释为A subclass of ValueAnimator that allows you to set a target object and object property to animate,ValueAnimator多出的功能就是不仅可以计算位置,还可以将图形的新的位置上刷新出来.
  • AnimatorSet,Provides a mechanism to group animations together so that they run in relation to one another就是把很多动画组合起来进行刷新显示.

 

     2,what and how to use Evaluators

     Evaluators tell the property animation system how to calculate values for a given property.IntEvaluator/FloatEvaluator/ArgbEvaluator/TypeEvaluator.

     Using a typeEvaluator:

public class FloatEvaluator implements TypeEvaluator {
	public Object evaluate(float fraction, Object startValue, Object endValue) {
		float startFloat = ((Number) startValue).floatValue();
		return startFloat + fraction * (((Number) endValue).floatValue() - startFloat);
	}
}

 

 

     3,what and how to use interpolator

    A time interpolator defines how specific values in an animation are calculated as a function of time.

 

  • AccelerateDecelerateInterpolator先加速后减速,
  • accelerateInterpolator一直加速
  • AnticipateInterpolator:表示开始的时候向后然后向前甩
  • OvershootInterpolator:表示向前甩一定值后再回到原来置,
  • BounceInterpolator:表示动画结束的时候弹起,
  • CycleInterpolator:表示动画循环播放特定的次数,速率改变沿着正弦曲线
  • DecelerateInterpolator:表示在动画开始的地方快然后慢
  • LinearInterpolator:表示以常量速率改变
  • AnticipateOvershootInterpolator:开始的时候向后然后向前甩一定值后返回最后的值
  • TimeInterpolator,Aninterface that allows you to implement your own interpolator.

Using interpolators:

    AccelerateDecelerateInterpolator:

public float getInterpolation(float input) {
	return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
}

 

    LinearInterpolator:

public float getInterpolation(float input) {
    return input;
}

 

 

Animating with ValueAnimator/Animating with ObjectAnimator:这两种animator的运用方法见demo,demo中还包括了AnimatorSetanimatorListener的用法.

 

Animating Layout changes to ViewGroup:

 

刚才提到,perporty animation不仅可以用到view,还可以用到wiewgroup.

 

  • APPEARING:view正子出现的状态
  • CHANGE_APPEARING :view正在出现的父控件的状态
  • DISAPPEARING :view正子消失的状态
  • CHANGE_DISAPPEARING :view正在消失的父控件的状态
分享到:
评论

相关推荐

    解决-Dmaven.multiModuleProjectDirectory system propery is not set

    -Dmaven.multiModuleProjectDirectory system propery is not set错误的解决,就是没配置环境变量,或者配置有误

    QML学习资料~~~~

    别人总结的QML学习资料,对学校QML有一定帮助

    Elastic property of fcc metal nanowires via an atomic-scale analysis

    基于原子尺度的fcc金属纳米线材杨氏模量分析,乔力,郑晓静,本文给出了一种从原子间相互作用规律出发的fcc金属纳米线材杨氏模量的简单分析方法。通过考察金属纳米线材组成结构单元的微观特性

    ExtJs扩展之GroupPropertyGrid代码

    ExtJs本身就提供了丰富的空间和良好的界面开发,就如同WinForm的开发一样。但是ExtJs的空间也有不完美的地方,但是有缺点也有他自己的弥补方法。ExtJs的良好的扩展性就是ExtJs自己控件不能实现的最好的方法。...

    universal:与Angular Universal一起使用的通用软件包的对应版本

    在其他情况下,您将获得类型安全的模拟,并且至少可以确保cannot read propery of null或undefined is not a function cannot read propery of null undefined is not a function SSR中undefined is not a function...

    main:W15-2j团队CS2103项目

    额外功能:可学习的自然语言处理 构建用户模型 cd directory java -cp stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop propery_file_name.prop 截屏 用户指南 对于命令行界面,用户可以使用以下...

    最新Ehlib 5.2.84(含完整源代码,支持delphi XE)

    + Propery RowDetailPanelControl is added in public section. Use this property to add components on panel of detail information at RunTime. Use next code: MyControl.Parent := DBGridEh1....

    vendormac:来自http的简单构建供应商mac映射文件

    Vendormac 这是用于生成Vendor Mac Map(例如Propery文件,xml文件和apple枚举元素)的简单实用程序。前提来自源文件。 另存为oui.txt(默认源文件名) 注意:定期需要更新用法 cmd&gt; java -jar vendormac.jarcmd&gt; ...

    kefir.db:基于Kefir的React式状态管理工具包

    该库基于本机Propery ,添加了许多其他功能,最重要的是,为可插入中间件建立了API。 用法 $ npm install kefir.db import K from "kefir" import * as D from "kefir.db" let inc = ( x ) =&gt; x + 1 let dec = ( x ...

    ElementQuery:一个用于创建 css 元素查询的小 api。 当媒体还不够时

    在以下示例中,有 4 个主要部分: [{min / max} - {propery} ~= "{value}(unit)" ][ min-width ~= "40em" ] 按照计算顺序,首先有一个属性或查询类型,通常可以与其他数字表示变量(例如宽度、纵横比或面积)互换。...

    WPTools.v6.29.1.Pro

    ******************************************* ************ WPTOOLS 6 History ************ ... Ziersch and **** **** WPCubed GmbH, Munich, Germany ******** ******************************************* ...

    DbfDotNet_version_1.0_Source

    Creating a record and accessing its propery is only what you need. Very small memory footprint Last time I checked the dbfDotNet dll was 50Kb. Other databases are 1Mb to 10Mb. I would appreciate if...

    C#读取JPEG图片的Exif信息

    [Serializable] public class EXIF { #region -- Class level members -- // Class level members. private Image _picture; #endregion #region -- Constructors -- // Constructors. ...

Global site tag (gtag.js) - Google Analytics