• ViewAnimator实现复杂的动画效果


    咱们先看个原生的

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
      ObjectAnimator.ofFloat(image,"translationY",-1000,0),
      ObjectAnimator.ofFloat(image,"alpha",0,1),
      ObjectAnimator.ofFloat(text,"translationX",-200,0)
    );
    animatorSet.setInterpolator(new DescelerateInterpolator());
    animatorSet.setDuration(2000);
    animatorSet.addListener(new AnimatorListenerAdapter(){
        @Override public void onAnimationEnd(Animator animation) {
     
          AnimatorSet animatorSet2 = new AnimatorSet();
          animatorSet2.playTogether(
              ObjectAnimator.ofFloat(image,"scaleX", 1f, 0.5f, 1f),
              ObjectAnimator.ofFloat(image,"scaleY", 1f, 0.5f, 1f)
          );
          animatorSet2.setInterpolator(new AccelerateInterpolator());
          animatorSet2.setDuration(1000);
          animatorSet2.start();
     
        }
    });
    animatorSet.start();

    很凌乱 现在我们用ViewAnimator来实现看看效果

    ViewAnimator
           .animate(image)
                .translationY(-1000, 0)
                .alpha(0,1)
           .andAnimate(text)
                .dp().translationX(-20, 0)
                .decelerate()
                .duration(2000)
           .thenAnimate(image)
                .scale(1f, 0.5f, 1f)
                .accelerate()
                .duration(1000)
           .start();

    就这么几行

    andAnimate 代表同时进行动画
    thenAnimate代表执行完下一个动画组

    项目中linlayout进入 停顿加 飞走的动画 可以参考下
     ViewAnimator.animate(ll_fans_join_msg)
                    .alpha(0, 1)
                    .translationX(ll_fans_join_msg.getWidth(), 0)
                    .descelerate()//减速
                    .duration(300)
    
                    .thenAnimate(ll_fans_join_msg)
                    .alpha(1, 1)
                    .translationX(-ll_fans_join_msg.getHeight())
                    .descelerate()//减速
                    .duration(1250)
    
                    .thenAnimate(ll_fans_join_msg)
                    .alpha(1, 0)
                    .translationX(-1.2f * ll_fans_join_msg.getWidth())
                    .accelerate()//加速
                    .duration(250)
                    .onStop(new AnimationListener.Stop() {
                        @Override
                        public void onStop() {
                            TCSimpleUserInfo userInfo = null;
                            try {
                                userInfo = fansJoinList.remove(0);
                            } catch (Exception e) {
    
                            }
                            if (userInfo != null) {
                                showFansJoin(userInfo,false);
                            } else {
                                isFansJoinShowing = false;
                            }
                        }
                    })
                    /*.startDelay(2000)*/
                    .start();
    总体来说很方便能满足绝大多数需求
    by磊磊tua
     
  • 相关阅读:
    [网鼎杯 2018]Comment-Git泄露部分
    Google Hacking 详解
    macOS修改Docker容器的端口映射配置
    CentOS6 7 8更换阿里yum源
    XSS代码合集(含测试效果详细版)-HTML4与更早版本的向量2
    VMware 启动Ubuntu时黑屏
    XSS代码合集(含测试效果详细版)-HTML4与更早版本的向量1
    APP安全在线检测网站
    Juice-Shop 二星题
    慕课网-安卓工程师初养成-4-5 练习题
  • 原文地址:https://www.cnblogs.com/widgetbox/p/10340639.html
Copyright © 2020-2023  润新知