首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓ObjectAnimator冻结用户界面

安卓ObjectAnimator冻结用户界面
EN

Stack Overflow用户
提问于 2014-06-10 06:43:03
回答 1查看 927关注 0票数 2

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

我读到把它放在一个Runnable中不是解决方案。所以我不知所措。

最终,我想让每个对象根据对象的大小使用不同的持续时间,这样动画在较小的圆圈上运行得更快,在较大的圆圈上运行得较慢。

下面是我用来测试动画的代码:

代码语言:javascript
复制
    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();
EN

回答 1

Stack Overflow用户

发布于 2014-06-10 11:06:51

尝试改用value animator:

创建一个返回ValueAnimator的方法:

代码语言:javascript
复制
 public static ValueAnimator animate(float from, float to, long duration) {
        ValueAnimator anim = ValueAnimator.ofFloat(from, to);
        anim.setDuration(duration);
        return anim;
    }

然后在哪里使用它,例如,如果您想要设置名为ImageView的imageView的比例,请执行以下操作

代码语言:javascript
复制
//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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24130210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档