2

我在我的应用程序中做一些动画。工作正常,除了一个小细节。在动画完成之前,UI 没有响应。我不能滚动,不能做任何其他事情。

我读到将其放入 Runnable 不是解决方案。所以我输了。

最终,我希望每个对象根据对象的大小使用不同的持续时间,以便动画在较小的圆圈上运行得更快,而在较大的圆圈上运行得更慢。

这是我必须测试我的动画的代码:

    HoleView holeView = (HoleView) view.findViewById(R.id.holeView1);
    ObjectAnimator oa1 = ObjectAnimator.ofInt(holeView, "animationTime", 0, holeView.getAnimationTime());
    oa1.setDuration(holeView.getAnimationTime());

    holeView = (HoleView) view.findViewById(R.id.holeView2);
    ObjectAnimator oa2 = ObjectAnimator.ofInt(holeView, "animationTime", 0, holeView.getAnimationTime());
    oa2.setDuration(holeView.getAnimationTime());

    holeView = (HoleView) view.findViewById(R.id.holeView3);
    ObjectAnimator oa3 = ObjectAnimator.ofInt(holeView, "animationTime", 0, holeView.getAnimationTime());
    oa3.setDuration(holeView.getAnimationTime());

    holeView = (HoleView) view.findViewById(R.id.holeView4);
    ObjectAnimator oa4 = ObjectAnimator.ofInt(holeView, "animationTime", 0, holeView.getAnimationTime());
    oa4.setDuration(holeView.getAnimationTime());

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(oa1).with(oa2).with(oa3).with(oa4);
    animatorSet.start();
4

1 回答 1

0

尝试使用 value animator 代替:

创建一个返回 ValueAnimator 的方法:

 public static ValueAnimator animate(float from, float to, long duration) {
        ValueAnimator anim = ValueAnimator.ofFloat(from, to);
        anim.setDuration(duration);
        return anim;
    }

然后,如果您想设置名为 imageView 的 ImageView 的比例,则在使用它的地方执行以下操作

//where 0 is the start value, 1 is the end value, and 850 is the duration in milliseconds
ValueAnimator imageAnimator = animate(0, 1, 850);

imageAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator anim) {
            float scale = (Float) anim.getAnimatedValue();
            imageView.setScaleX(scale);
            imageView.setScaleY(scale);
        }
    });

 imageAnimator.start();
于 2014-06-10T03:06:50.570 回答