当前位置:操作系统 > 安卓/Android >>

Android animation学习笔记之propery animation

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

 

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

 

    property animation介绍如下,如果懒得看,可直接点击连接下载demo查看,demo地址。

 

 

    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,translate和alpha操作.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

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

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

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

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

     3,ViewPropertyAnimator

[java]
?myView.animate().x(50f).y(100f); 

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中可以设置三种动画属性:

ValueAnimator - <animator>
ObjectAnimator - <objectAnimator>
AnimatorSet - <set>
用法如下:

[java]
<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> 

<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="50

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,