• 动画效果 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();
  • 相关阅读:
    inline-block 文字与图片不对齐
    js去除数组重复项
    react2
    kfaka windows安装
    sigar 监控服务器硬件信息
    Disruptor
    Servlet 3特性:异步Servlet
    jvmtop 监控
    eclipse如何debug调试jdk源码
    一致性hash算法
  • 原文地址:https://www.cnblogs.com/kongbb/p/10537680.html
Copyright © 2020-2023  润新知