• 动画效果 ObjectAnimator


    学习了一下动画效果的使用,做一下笔记

    ImageView imageView = findViewById(R.id.imageView);
    ObjectAnimator.ofFloat(imageView,"translationY",0F,200F)
    .setDuration(1000).start();//translationX也可以
    
    ObjectAnimator.ofFloat(imageView,"rotation",0F,360F)
    .setDuration(1000).start();//旋转360度
    //这里是多个动画同时实现 Y方向上的平移与自身的旋转
    PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("rotation",0,360F);
    PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationX",0,200F);
    PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("translationY",0,200F);
    //设置三个动画
    ObjectAnimator.ofPropertyValuesHolder(imageView,p1,p2,p3).setDuration(1000).start();
    // 先传入控件 然后是个可变长的数组
    ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView,"rotation",0,360F);
    ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,"translationX",0,300F);
    ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,"translationY",0,300F);
    
    AnimatorSet set=new AnimatorSet();
    set.playTogether(animator1,animator2,animator3);//同时
    set.setDuration(1000);
    set.start();
    ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView,"rotation",0,360F);
    ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,"translationX",0,300F);
    ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,"translationY",0,300F);
    
    AnimatorSet set = new AnimatorSet();
    set.playSequentially(animator1,animator2,animator3);//按照顺序开始动画
    set.setDuration(1000);
    set.start();

    通过with,after,before来定义多个动画之前的先后顺序

    set.play(animator2).with(animator3);
    set.play(animator1).after(animator2);
    ObjectAnimator animator = ObjectAnimator.ofFloat(view,"alpha",0F,1F);//设置透明度
    animator.setDuration(1000);// 1000ms
    animator.addListener(new AnimatorListenerAdapter() {//设置监听器
      //这里只重写了 end的监听,也可以重写 start等监听 @Override
    public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation);//end时 toast Toast.makeText(MainActivity.this,"anim end",Toast.LENGTH_SHORT).show(); } }); animator.start();
  • 相关阅读:
    替换html里面的 及解决记事本中的每个段落只有一行的情形
    关于 'list' object has no attribute 'select'
    python写爬虫的弯路
    将博客搬至CSDN
    转载:如何让spring mvc web应用启动时就执行
    java开发人员,最应该学习和熟练使用的工具类。google guava.(谷歌 瓜娃)
    解决svn问题:Wrong committed revision number: -1
    生产环境中,数据库升级维护的最佳解决方案flyway
    在JaveWeb项目中配置Spring 匿名访问时,匹配规则的变相实现/*
    nexus的使用
  • 原文地址:https://www.cnblogs.com/kongbb/p/10537680.html
Copyright © 2020-2023  润新知