Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to chain animation in android to the same view?

I got some text views and I want to make the buzz effect of MSN.

My plan is:

  • take the view, let say 10dip to the left,
  • take it back to its start position
  • after that take it 10dip up
  • then back
  • down back
  • left... and so on.

My point is, I have some sequence of movements that I want to set to one view and that needs to execute one after another.

How can I do that?

like image 612
Lukap Avatar asked Jun 07 '11 15:06

Lukap


People also ask

What are the two different types of view animations in Android?

The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.

Is animation possible on 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.


1 Answers

You probably mean AnimatorSet (not AnimationSet). As written in documentation:

This class plays a set of Animator objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.

There are two different approaches to adding animations to a AnimatorSet: either the playTogether() or playSequentially() methods can be called to add a set of animations all at once, or the play(Animator) can be used in conjunction with methods in the Builder class to add animations one by one.

Animation which moves view by -100px for 700ms and then disappears during 300ms:

final View view = findViewById(R.id.my_view);

final Animator translationAnimator = ObjectAnimator
        .ofFloat(view, View.TRANSLATION_Y, 0f, -100f)
        .setDuration(700);

final Animator alphaAnimator = ObjectAnimator
        .ofFloat(view, View.ALPHA, 1f, 0f)
        .setDuration(300);

final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(
        translationAnimator,
        alphaAnimator
);
animatorSet.start()
like image 167
pawel-schmidt Avatar answered Oct 23 '22 05:10

pawel-schmidt