0

I'm attempting to use rotate to give a view the semblance of shaking side to side. I've attempted to define the animation programmatically and am using animationset to loop it as suggested in this question. However on execute the code doesn't seem to be doing anything at all.

AnimationSet set = new AnimationSet(true);

RotateAnimation rotright = new RotateAnimation(0.0f, 20.0f,
        Animation.RELATIVE_TO_SELF, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f);
rotright.setDuration(0);
set.addAnimation(rotright);

RotateAnimation rotleft = new RotateAnimation(0.0f, 340.0f,
        Animation.RELATIVE_TO_SELF, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f);
rotleft.setDuration(0);
set.addAnimation(rotleft);

blender.startAnimation( set );
}
};

Any clues as to how exactly I've messed up would be greatly appreciated.

Community
  • 1
  • 1

1 Answers1

2
rotright.setDuration(0);

rotleft.setDuration(0);

You've set the duration of the two animations to 0, effectively creating instant rotations, which results in no animation at all. Try setting some values greater than zero - remember you're setting milliseconds.

MH.
  • 45,303
  • 10
  • 103
  • 116
  • Much appreciated. If I might extend my question, it isn't looping still. Any idea why? – user1398478 May 01 '13 at 05:56
  • @user1398478: Have you set [`setRepeatMode(int)`](http://developer.android.com/reference/android/view/animation/AnimationSet.html#setRepeatMode%28int%29) on your `AnimationSet`? I don't see it in your original code snippet. You can pass in either `Animation.RESTART` or `Animation.REVERSE`, depending on the desired effect. – MH. May 01 '13 at 06:07