0

In my app, i am playing with android translation animation. I want to translate view from top right of screen to bottom left of the screen. I can translate the view. Now i want to pause the translation for some seconds in mid and then i want resume it. I have tired playing around with different interpolators. Those doesn't give the required result. Can someone tell me how can i achieve this kind of translation?

I am sharing the code that i am using for the translation.

 AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(1f, 2f,
                1f, 2f,
                ScaleAnimation.RELATIVE_TO_PARENT, .5f,
                ScaleAnimation.RELATIVE_TO_PARENT, .1f);
        animationSet.addAnimation(scale);
        int size[] = MainActivity.getDisplaySize(this);
        TranslateAnimation animation = new TranslateAnimation(-1000, 1500, 300, 850);
        animationSet.addAnimation(animation);
        animationSet.setDuration(6000);
        animationSet.setFillAfter(false);
        animationSet.setInterpolator(new FastOutLinearInInterpolator());
        animationSet.setAnimationListener(new MyAnimationListener());
        imageView.startAnimation(animationSet);

Thanks!

Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74

1 Answers1

1

A common solution is to split up the animation into 2 seperate animations.

So you have to start the 2nd animation after your desired pause.

An other approach is to save the play time when you pause with() getCurrentPlayTime() and restart the animation at this time via setCurrentPlayTime().

daemmie
  • 6,361
  • 3
  • 29
  • 45
  • I liked the second solution but i am using ```AnimationSet``` and ```TranslationAnimation``` class. The methods you pointed out are for ```ValueAnimator``` class. – Zeeshan Shabbir May 19 '17 at 05:17
  • Yeah I know. But I don't know if this is possible. I thought you might use the ViewPropertyAnimator instead of the AnimationSet? Should work nice with you current animation? – daemmie May 19 '17 at 05:57
  • Can i scale and translate an view with ```ViewPropertyAnimator```? Sorry i never worked with animatons in android before. I took start with ```Animation``` – Zeeshan Shabbir May 19 '17 at 06:02
  • Yes. Something lile `view.animate() .scaleX(1).scaleY(1).translateX(1000).translateY(1000).start()` – daemmie May 19 '17 at 06:10
  • thanks, but i want to specify the start position as well. – Zeeshan Shabbir May 19 '17 at 06:13
  • how would you convert these translation animation ```TranslateAnimation(-1000, 1500, 300, 850)``` to ```ViewPropertyAnimator``` – Zeeshan Shabbir May 19 '17 at 06:16
  • Start pos: `view.animate().translateX(-1000).translateY(1500).setDuration(0).start().` then `view.animate().translateX(300).translateY(850).setDuration(6000)..start())`. – daemmie May 19 '17 at 06:18