Tween uses detailed

Highly recommended article: Welcome Favorite
Android Dry Share

Reading five minutes, ten o'clock daily, lifelong learning with you, here is the Android programmer

This article describes the Androidpart of the development of knowledge by reading this article, you will reap the following:

  1. Transparent animated AlphaAnimation
  2. Rotation animation ScaleAnimation
  3. Zoom animation RotateAnimation
  4. Panning animation TranslateAnimation
  5. Animation collection AnimationSet
  6. XML achieve four kinds of animation

Animation Androidwill often be used in development, good animation can achieve a multiplier effect. Tween is Androidone of the commonly used animation, relatively speaking property animation, tween click event will not follow the change in position of the animation changes. Follow-up will gradually be replaced property animation.

1. transparent animation

  • AlphaAnimation
        /**
         * 透明度动画AlphaAnimation 从不透明到完全透明
         * **/
        // 起始透明度 到结束透明度 不透明到透明(1f-0f)
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        // 动画执行时间
        alphaAnimation.setDuration(4000);
        // 设置重复次数
        alphaAnimation.setRepeatCount(2);
        // 重复模式
        alphaAnimation.setRepeatMode(Animation.RESTART);
        // alphaAnimation.setRepeatMode(Animation.REVERSE);
        // 保持结束时候的状态
        alphaAnimation.setFillAfter(true);
        mImageView.startAnimation(alphaAnimation);

2. rotation animation

  • RotateAnimation

        /**
         * 旋转动画RotateAnimation,旋转360度
         **/

        RotateAnimation rotateAnimation = new RotateAnimation(0, 360);
        rotateAnimation.setDuration(2000);
        rotateAnimation.setRepeatCount(2);
        mImageView.startAnimation(rotateAnimation);

3. zoom animation

  • ScaleAnimation
        /**
         * 缩放动画 ScaleAnimation使用方法 缩放2倍
         * */
        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 2, 1, 2);
        scaleAnimation.setDuration(2000);
        scaleAnimation.setRepeatCount(2);
        scaleAnimation.setRepeatMode(Animation.RESTART);
        mImageView.startAnimation(scaleAnimation);

4. panning animation

  • TranslateAnimation
        /***
         * 平移动画TranslateAnimation 从x,y 轴 从(0,0)平移到(300,200) *
         **/
        TranslateAnimation translateAnimation = new TranslateAnimation(0,
                300.f, 0, 200.f);
        translateAnimation.setDuration(2000);
        translateAnimation.setRepeatCount(2);
        translateAnimation.setRepeatMode(Animation.RESTART);
        mImageView.startAnimation(translateAnimation);

5. animation collection

  • AnimationSet
    /***
         * 动画集合使用效果如下:
         * ***/
        AnimationSet sets = new AnimationSet(true);

        AlphaAnimation alphaAnimation1 = new AlphaAnimation(0.0f, 1.0f);
        TranslateAnimation translateAnimation1 = new TranslateAnimation(0,
                100.f, 0, 100.f);
        RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360);
        ScaleAnimation scaleAnimation1 = new ScaleAnimation(1, 2, 1, 2);

        // 将动画添加到set集合中
        sets.addAnimation(alphaAnimation1);
        sets.addAnimation(translateAnimation1);
        sets.addAnimation(rotateAnimation1);
        sets.addAnimation(scaleAnimation1);

        sets.setDuration(4000);
        sets.setRepeatCount(2);
        sets.setRepeatMode(Animation.RESTART);
        mImageView.startAnimation(sets);

6. XML achieve animation effects

  • 1. animation XMLfile belongsres/anim/hyperspace_jump.xml

XML achieve animation effects

  • 2. Picture Loadanimation xmlfile

Load xml file as a picture

So far herein, this has ended, if the wrong place, welcome your suggestions and corrections. At the same time look forward to your attention, thank you for reading, thank you!

Micro-channel public concern number: Programmer Android, receive welfare

Guess you like

Origin www.cnblogs.com/wangjie1990/p/11323705.html