Android Animations 用法

Animations 可分为两大类:

Tweened Animations,该类Animations提供了旋转,移动,伸展,和淡入淡出等效果

Frame-by-Frame Animations ,该类Animations 可以创建一个Drawable序列,这些Drawable可能按照指定的时间一个一个的显示,类似于电影.

Tweened Animations 有这4种分类

1 Alpha         淡入淡出

2 Rotate       旋转

3 Scale          缩放

4 Translate     移动

使用Tweened Animations 的步骤

1.  创建一个Animations 对象

2.  根据需要创建相应的Animation对象

3.  按照需求,为Animation 对象设置相应的数据

4.  将Animation对象添加到AnimationSet对象当中

5.  使用控件对象开始执行AnimationSet  

各种Animation 的主要属性 

Animation type           |             attributes                 |               valid  values               

     Alpha                             fromAlpha/toAlpha                       Float  from 0  to  1

     Scale                            fromXScale/toXScale                      Float  from 0 to   1

                                        fromYScale/toYScale                      Float  from 0 to    1

                                        pivotX/pivotY                                String of the percentage of graphic

                                                                                           width/height from 0% to 100%

   Translate                        fromX/to X                                   Float from 0 to 1

                                        from Y/to Y                                   Float from 0 to 1

   Rotate                          fromDegrees/toDegrees                  Float from 0 to 360

                                       pivotX/pivotY                                String of the percentage of graphic

                                                                                           width/height from 0% to 100%

------------------------------------------------------------------------------------------

 Tween Animations 的通用属性

1. setDuration(long durationMills)  设置动画持续时间(单位:毫秒)

2. setFillAfter(boolean fillAfter)  如果fillAfter为true,表示动画执行后,控件将停留在执行结束的状态

3. setFillBefore(boolean fillBefore) 如果fillBefore 的值为true,表示动画执行后,控件将回到动画执行之前的状态

4. setStartOffSet(long startOffSet)  设置动画执行之前的等待时间

5. setRepeatCount(int count)  设置动画重复执行的次数

----------------------------------------------------------------------------------------

下面再介绍Animations 另一种使用方法

1.  在res文件夹下面新建一个名为anim的文件夹;

2.  创建xml文件,并首先加入set标签,改标签如下:

    

           android:interpolator="@android:anim/acccelerate_interpolator" >

    

3. 在该标签当中可以加入rotate,alpha,scale,translate标签

4. 在代码当中使用AnimationUtils 类 装载xml文件,并生成   Animation  对象

在rotate.xml文件中

android:pivotX的值共有三种设置方法:

1.  android:pivotX="50"  使用绝对位置定位

2.  android:pivotX="50%"  使用相对于控件本身定位

3.  android:pivotX="50%p"  使用相对于控件的父控件定位


具体代码 请参见 animationsTest, animationsTest2animationsTest3 工程


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部