【问题标题】:animate by 180 degrees - clicking twice results in random rotation values动画 180 度 - 单击两次会产生随机旋转值
【发布时间】:2017-01-15 07:57:19
【问题描述】:

我用 image.animate().rotationBy(180).setInterpolator(new DecelerateInterpolator()).start(); 对于 180 旋转动画。

但是,如果我快速按两次图标,我最终会得到这样的结果:

【问题讨论】:

    标签: android user-interface animation rotation icons


    【解决方案1】:

    您可以在轮换开始时添加代码imageView.setEnabled(false),在轮换结束时添加imageView.setEnabled(true)。代码:

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ImageView imageView  = (ImageView)findViewById(R.id.img);
        final ViewPropertyAnimator viewPropertyAnimator = imageView.animate();
        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                imageView.setEnabled(false);
            }
    
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                imageView.setEnabled(true);
            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPropertyAnimator.rotationBy(180).setDuration(2000).setInterpolator(new DecelerateInterpolator()).start();
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多