`
flycomos.lee
  • 浏览: 275992 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android 动画详解

 
阅读更多

Tween动画又称“补间动画”、“中间动画”,这并不重要,就好像很多人都知道鲁迅,却不知道他叫:周树人。

   Tween动画在Android中分为4类,它们分别是:AlphaAnimation(透明度动画)、TranslateAnimation(平移动 画)、ScaleAnimation(缩放动画)、RotateAnimation(旋转动画)。都继承自android.view.Animation 类,它们都是表示从一个状态A向状态B变化的一个过程,所以英文名字叫Tween动画、中文名叫:“补间动画”、“中间动画”。它们总的说来有两种实现方 式:java code(java源代码)、xml(xml配置文件),这里先从java code开始

   以前就是因为每中Tween动画都有很多构造函数不清楚,现在仔细看了下,记录下来方便以后查看

    AlphaAnimation(透明度动画)

     AlphaAnimation有两个构造函数,分别是:

                       —— AlphaAnimation (Context context, AttributeSet attrs):第二个参数是个属性集,之后会详细对AttributeSet 讲解

                       ——AlphaAnimation (float fromAlpha, float toAlpha):第一个参数是初始透明度,第二个参数是终止透明度

    TranslateAnimation(平移动画)

     TranslateAnimation有三个构造函数,分别是:

                       ——TranslateAnimation (Context context, AttributeSet attrs):略过

                       ——TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta):分别对应x轴的起始、终点                                          坐标,与y轴的起始、终点坐标

                      ——TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int                                 toYType, float toYValue):第一个参数是x轴方向的值的参照(Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF,                                 or Animation.RELATIVE_TO_PARENT);第二个参数是第一个参数类型的起始值;第三个参数与第四个参数是x轴方向的

                              终点参照与对应值;后面四个参数就不用解释了。如果全部选择Animation.ABSOLUTE,其实就是第二个构造函数。

                              以x轴为例介绍参照与对应值的关系

                              如果选择参照为Animation.ABSOLUTE,那么对应的值应该是具体的坐标值,比如100到300,指绝对的屏幕像素单位

                              如果选择参照为Animation.RELATIVE_TO_SELF或者 Animation.RELATIVE_TO_PARENT指的是相对于自身或父控件,

                              对应值应该理解为相对于自身或者父控件的几倍或百分之多少。一定要多试试这几个参数类型!

       ScaleAnimation(缩放动画)

        ScaleAnimation(缩放动画)有四个构造函数,分别是:

                       ——ScaleAnimation (Context context, AttributeSet attrs):略过

                       ——ScaleAnimation (float fromX, float toX, float fromY, float toY):同TranslateAnimation (float fromXDelta, float toXDelta,                                    float fromYDelta, float toYDelta)

                       ——ScaleAnimation (float fromX, float toX, float fromY, float toY, float pivotX, float pivotY):这里解释后面两个参数,pivot

                               英文意思为“枢轴”,也就是支点。通过这两个参数可以控制缩放动画的放大方向,这个点不会随对象大小变化而变化

                      ——ScaleAnimation (float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float                                       pivotYValue):如果理解了前面所讲的,这个就不做多的说明,如果不清楚,请回头多用代码试试。

        RotateAnimation(旋转动画)

          RotateAnimation(旋转动画)同样有四个构造函数,分别是:

                      ——RotateAnimation (Context context, AttributeSet attrs)

                     ——RotateAnimation (float fromDegrees, float toDegrees)

                     ——RotateAnimation (float fromDegrees, float toDegrees, float pivotX, float pivotY)

                     ——RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float                                                pivotYValue)

                    这里不废话了!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics