动画

Animation的分类

1.scaleAnimation
2.alphaAnimation
3.translateAnimation
4.rotateAnimation
5.animationSet

设置动画开始

 public void start() 

设置动画持续时间

public void setDuration(long durationMillis)

设置动画延迟开始

 public void setStartOffset(long startOffset)

设置动画重复次数

public void setRepeatCount(int repeatCount)

设置动画结束时候归0

public void setFillBefore(boolean fillBefore)

设置动画结束不归0

public void setFillAfter(boolean fillAfter)

设置动画的监听

 public void setAnimationListener(AnimationListener listener) 
 public static interface AnimationListener {
        /**
         * <p>Notifies the start of the animation.</p>
         *
         * @param animation The started animation.
         */
        void onAnimationStart(Animation animation);

        /**
         * <p>Notifies the end of the animation. This callback is not invoked
         * for animations with repeat count set to INFINITE.</p>
         *
         * @param animation The animation which reached its end.
         */
        void onAnimationEnd(Animation animation);

        /**
         * <p>Notifies the repetition of the animation.</p>
         *
         * @param animation The animation which was repeated.
         */
        void onAnimationRepeat(Animation animation);
    }

设置动画的速率等比如线性 开始快 结束慢等

 public void setInterpolator(Interpolator i)

动画常见参数

 public ScaleAnimation(float fromX, float toX, float fromY, float toY,
            int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 
刚开始的比例  结束的比例
pivotXType:
               Animation.ABSOLUTE, 
               Animation.RELATIVE_TO_SELF, or
     *          Animation.RELATIVE_TO_PARENT.
后4个参数确定锚点

从xml文件中加载动画

Animation loadAnimation = AnimationUtils.loadAnimation(this, R.anim.myscale);
        findViewById.setAnimation(loadAnimation);

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="2"
    android:toXScale="1"
    android:fromYScale="2"
    android:toYScale="1"
    android:pivotX="0.5"
    android:pivotY="0.5"
    android:duration="5000"
    >
</scale>

绝对是 100
相对自己是 100%
相对父亲是100%p

设置animationset的时候如果想第二个动画开始的时候是第一个动画结束的时间那么需要设置第二个动画的延迟时间

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让全面说说Android的动画,所以今...
    未聞椛洺阅读 2,735评论 0 10
  • 先看看CAAnimation动画的继承结构 CAAnimation{ CAPropertyAnimation { ...
    时间不会倒着走阅读 1,678评论 0 1
  • Animation Animation类是所有动画(scale、alpha、translate、rotate)的基...
    四月一号阅读 1,934评论 0 10
  • 转载一篇高质量博文,原地址请戳这里转载下来方便今后查看。1 背景不能只分析源码呀,分析的同时也要整理归纳基础知识,...
    Elder阅读 1,953评论 0 24
  • 第9课 英语语法与阅读 想写好作文,看作文大全是不行的?! 行! 那也得是大量的作文大全! 坚持! 我要走到这一步。
    Pheeb阅读 282评论 0 1