I have two linear layouts which I want to perform two different animation on both of these layouts and at the same time.
Now its working in sequential manner. i.e, after completing one its starting another.
here is my code.
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.menu:
mainLayout.startAnimation(outtoLeft);
sideBar.startAnimation(inFromRight);
break;
}
}
outtoLeft.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
mainLayout
.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT, 40));
}
});
The way to solve this problem is to use an AnimatorSet with Animator objects. If you are worried about backwards compatibility, you can use the NineOldAndroids library to bring the API back all the way to Android 1.0
In your Activity
Then, in yourAnimation.xml define all the animations you want
I solved it starting second animation in onAnimationStart event of the first animation. In my example right layout replacing left one, both of them are moving left at the same time. I use animate property of a View class http://developer.android.com/reference/android/view/View.html#animate() which is available starting API v.12
I think you need to use an
AnimationSet
.From the doc:
Here you can see how an
AnimationSet
is supposed to be.