zoukankan      html  css  js  c++  java
  • Android属性动画-简单实例

    1.ValueAnimator

    //在2000毫秒内,将值从0过渡到1的动画
            ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
            anim.setDuration(2000);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    float currentValue = (float) valueAnimator.getAnimatedValue();
                    Log.e("tag", "currentValue="+currentValue);
                    String textStr = ((int) (currentValue * 60)) + "";
                    text1_tv.setText(textStr);
                }
            });
            anim.start();

    2.ObjectAnimator

    //将TextView从常规变换成全透明,再从全透明变换成常规
            ObjectAnimator anim1 = ObjectAnimator.ofFloat(text2_tv, "alpha", 1f, 0f, 1f);
            anim1.setDuration(3000);
            anim1.start();
            //将TextView进行一次360度的旋转
            ObjectAnimator anim2 = ObjectAnimator.ofFloat(text2_tv, "rotation", 0f, 360f);
            anim2.setDuration(3000);
            anim2.start();
            //将TextView先向左移出屏幕,然后再移动回来
            float curTranslationX = text2_tv.getTranslationX();
            ObjectAnimator anim3 = ObjectAnimator.ofFloat(text2_tv, "translationX", curTranslationX, -500f, curTranslationX);
            anim3.setDuration(3000);
            anim3.start();
            //将TextView在垂直方向上放大3倍再还原
            ObjectAnimator anim4 = ObjectAnimator.ofFloat(text2_tv, "scaleY", 1f, 3f, 1f);
            anim4.setDuration(5000);
            anim4.start();

    3.组合动画

    //让TextView先从屏幕外移动进屏幕,然后开始旋转360度,旋转的同时进行淡入淡出操作
            ObjectAnimator moveIn = ObjectAnimator.ofFloat(text3_tv, "translationX", -500f, 0f);
            ObjectAnimator rotate = ObjectAnimator.ofFloat(text3_tv, "rotation", 0f, 360f);
            ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(text3_tv, "alpha", 1f, 0f, 1f);
            AnimatorSet animSet = new AnimatorSet();
            animSet.play(rotate).with(fadeInOut).after(moveIn);
            animSet.setDuration(5000);
            animSet.start();

     

  • 相关阅读:
    SQL计算生日所属的星座 XuZhao
    IIS 操作系统 .net FrameWork 的一些常见问题
    Python面向对象4.实例属性、实例方法
    Python面向对象6.init方法
    Python面向对象3.定义类、创建对象
    源码部署zabbix4.0监控
    IE6 Select控件挡住DIV内容解决办法
    转自网上的c#日期大全
    已更新或者删除的行值不能使该行成为唯一行(sql2005) 解决办法
    asp 多行多列加分页代码
  • 原文地址:https://www.cnblogs.com/chenzheng8975/p/10869333.html
Copyright © 2011-2022 走看看