1

I am trying the "slide" animation two view that are one on top of another (y exiss).

This is what I am doing:

TranslateAnimation precentageTranslateAnim = new TranslateAnimation(0, 0, shareBtnsHeight, 0);
precentageTranslateAnim.setDuration(TRANSLATE_ANIMATION_DURATION);
DecelerateInterpolator interpulator = new DecelerateInterpolator();
precentageTranslateAnim.setInterpolator(interpulator);
precentageLayout.setVisibility(View.VISIBLE);
precentageLayout.startAnimation(precentageTranslateAnim);
reactionsBtnsLayout.startAnimation(precentageTranslateAnim);

My problem is that when the animations happen, you can see that the views are not moving completely together.

There is a small line between them during the animation.

Is there a way to make synchronization between them?

Dhasneem
  • 4,037
  • 4
  • 33
  • 47
roiberg
  • 13,629
  • 12
  • 60
  • 91
  • Sounds like you are trying something like this: http://stackoverflow.com/questions/19098083/how-to-animate-a-slide-in-notification-view-that-pushes-the-content-view-down/19098369#19098369 please upvote if it helps you – cYrixmorten Dec 05 '13 at 10:05

1 Answers1

2

Because you are starting animation at different moments, You need to run them parallelly, for your help lucky android has ability of clubbing different animation and option of running them parallely. Perform the following.

  1. Create a AnimatorSet,
  2. Add both of your Object Animation in that set
  3. Play them together, this will make sure all your animation runs parallely so it will look synchronized.

http://developer.android.com/reference/android/view/animation/AnimationSet.html

read above link for more detail. Code below

ObjectAnimator animator1 = ObjectAnimator.ofFloat(precentageLayout, "y", shareBtnsHeight,0);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(reactionsBtnsLayout, "y", shareBtnsHeight,0); 
animator1.setDuration(TRANSLATE_ANIMATION_DURATION);
animator1.setDuration(TRANSLATE_ANIMATION_DURATION);
DecelerateInterpolator interpulator = new DecelerateInterpolator();
animator1.setInterpolator(interpulator);
animator2.setInterpolator(interpulator);
AnimatorSet set = new AnimatorSet();
set.playTogether(animator1,animator2);

set.start();
Techfist
  • 4,314
  • 6
  • 22
  • 32
  • 1
    Isn't animations set made to have more than one animation to one ONE view? in my case i have one kind of animation that I want to set on two views... Am I understanding it wrong? – roiberg Dec 05 '13 at 09:42
  • Its not like that, Animation Set can hold animations for multiple views at a time, just add your different animation in a set and play them together. – Techfist Dec 05 '13 at 09:47
  • But i have only ONE animation. both views are using the same animation. – roiberg Dec 05 '13 at 09:51
  • precentageLayout.startAnimation(precentageTranslateAnim); reactionsBtnsLayout.startAnimation(reactionBtnsTranslateAnim); this are your two animations right, just club precentageTranslateAnim,reactionBtnsTranslateAnim into a set and play. – Techfist Dec 05 '13 at 09:53
  • It's my mistake, it's the same animation. I edited the question. – roiberg Dec 05 '13 at 09:54
  • just posted code for you, use the animation I provided it will solve your issue. Its using Object animation rather then view animation, here you have the required capability of playing all the stuff at once. – Techfist Dec 05 '13 at 10:07
  • I saw animationSet instead of animatorSet :). sorry and thank you! – roiberg Dec 05 '13 at 10:10
  • No issues, Welcome :-) – Techfist Dec 05 '13 at 10:11