首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Value Animator android

Value Animator android
EN

Stack Overflow用户
提问于 2013-11-28 21:33:04
回答 1查看 14.2K关注 0票数 6

我正在尝试用value animator一个接一个地制作3个图像的动画,但是在常规的intervals..Suppose之后,我无法决定如何调用这三个处理程序。有3个图像,我正在制作三个用于动画them.But的处理程序。在常规的intervals.Please帮助中,我能够一次处理这三个图像,但不能一个接一个地执行。

这是我从我的处理程序调用的UpdateListener

代码语言:javascript
复制
public void startAnimation_image(final ImageView aniView) {

    animator = ValueAnimator.ofFloat(0, .8f);
    animator.setDuration(Constants.ANIM_DURATION);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        int Low = 10;
        int High = width-150;
        int R = (int) ((Math.random() * (High - Low)) + Low);

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = ((Float) (animation.getAnimatedValue())).floatValue();
            aniView.setTranslationX(R);

             Log.e("mscale",150*mScale +"");
             Log.e("value is", value+"");

            aniView.setTranslationY((mDisplaySize.bottom + (150*mScale))*value);

            x_point = aniView.getTranslationX();
            y_point = aniView.getTranslationY();
        }
    });

    animator.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator arg0) {

        }
        @Override
        public void onAnimationRepeat(Animator arg0) {

        }
        @Override
        public void onAnimationEnd(Animator arg0) {

            startAnimation();
        }
        @Override
        public void onAnimationCancel(Animator arg0) {

        }
    });

    animator.start();
}

这是我的一个训练员

代码语言:javascript
复制
@Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);

        //int viewId = new Random().nextInt(STARS.length);

         id =   getApplicationContext().getResources().getIdentifier(STARS[0], "drawable", 
          getApplicationContext().getPackageName());

         inflate = LayoutInflater.from(StarsActivity2.this);


        img[0].setVisibility(ImageView.VISIBLE);
        img[0].setImageResource(id);

        mAllImageViews.add(img[0]);         

        LayoutParams animationLayout = (LayoutParams) img[0].getLayoutParams();
        img[0].setLayoutParams(animationLayout);
        Log.e("mHandler",img[0]+ "");
        startAnimation_image(img[0]);           
    }
};

类似地,有三个处理程序和三个更新侦听器。请帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-28 23:15:10

可以通过调用offset ms来延迟动画

代码语言:javascript
复制
animation.setStartOffset(offset);

因此,对于三个持续时间为ANIM_DURATION的图像,您可以使用以下值按顺序启动它们(可能需要将它们作为参数传递给startAnimation_image())

代码语言:javascript
复制
// note: this is for illustrative purposes. You should put this in a loop
int firstOffset = 0 * ANIM_DURATION; // starts immediately
int secondOffset = 1 * ANIM_DURATION; // starts after the first animation is finished
int thirdOffset = 2 * ANIM_DURATION; // starts after the second animation is finished
// ... and so on.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20267572

复制
相关文章

相似问题

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