Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start two animations at same time in android?

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));              }         }); 
like image 657
Noby Avatar asked May 15 '12 17:05

Noby


People also ask

Can we do animation in Android?

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.

How many types of animation are there in Android?

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.

What are animations on Android phones?

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.


1 Answers

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.

like image 124
Gophermofur Avatar answered Sep 28 '22 07:09

Gophermofur