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)); } });
On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.
There are three animation systems that work differently for different cases but the most important are Property animations. Property animations allow us to animate any property of any object from one value to another over a specified duration. These can be applied to anything within the Android application.
Android devices display animations when they transition between apps, windows, and various menus. Animations oftentimes looks slick, but they do take up time—and sometimes can even cause the phone to lag if it's low on resources.
I think you need to use an AnimationSet
.
From the doc:
Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform.
Here you can see how an AnimationSet
is supposed to be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With