Reputation: 13747
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?
Upvotes: 1
Views: 238
Reputation: 4344
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.
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();
Upvotes: 2