I have some problems with animated buttons in android. This is my code:
private void RunAnimations() {
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
a.reset();
Button tv = (Button) findViewById(R.id.button1);
tv.clearAnimation();
tv.startAnimation(a);}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()== MotionEvent.ACTION_DOWN){
RunAnimations();
}
return false;
}
The problem is the animation will run if the screen OnTouch. I want the animation to run only one time. What should I add?
You could add a
booleanto your classanimationRun = false, thenI’d prefer to just remove the event handler after you play the animation, but I don’t really know the Android API so can’t help you there.