dfetter88
dfetter88

Reputation: 5391

How can I run a sequence of Animations? AnimationSet is failing me

I have a custom view Dial. This view has a custom animation DialAnimation that was written as a nested class of Dial. Below is the code from my Activity that instantiates Dial and attempts to perform a sequence of animations on it. When the code is run, only one of the animations is seen onscreen. What am I missing here?

Dial dial = (Dial) findViewById(R.id.dial);
DialAnimation anim1 = dial.new DialAnimation(0, 90, 3000);
DialAnimation anim2 = dial.new DialAnimation(180, 360, 3000);
anim2.setStartOffset(3500);

AnimationSet set = new AnimationSet(false);
set.addAnimation(anim1);
set.addAnimation(anim2);
dial.startAnimation(set);

Upvotes: 2

Views: 7068

Answers (3)

Terence
Terence

Reputation: 288

Add a .setDuration(3500) method to each animation and ensure that the time for the duration and the time for the .setStartOffset(3500) method for the secondanimation match.

Upvotes: -1

dharmendra
dharmendra

Reputation: 7881

try animation listner in doinbackground() method this will update your animation in sequence ..OR u can use simple thread in you application .

Upvotes: 0

FoamyGuy
FoamyGuy

Reputation: 46856

one way to do it would be to set an AnimationListener on the first animation and override the onAnimationEnd() to make it start the next animation in the sequence. That would look something like this:

animation1Listener = new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                 dial.startAnimation(animation2)
            }
}

animation1.setAnimationListener(animation1Listener);
dial.startAnimation(animation1);

Upvotes: 5

Related Questions