Reputation: 53600
In my android project I have an image that i want to rotate it and create animation for long time. I can run program and it works fine. but I don't know how can I stop it. if you know please tell me.
Thanks
This is my code, I have a menu with two items, When I click on Start item, startAnimation function runs and when I click on Stop item, stopAnimation runs.:
public class Hypnagogic extends Activity
{
ImageView imView;
Animation an;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView = (ImageView)findViewById(R.id.imView);
}
private void startAnimation()
{
an = AnimationUtils.loadAnimation(this, R.anim.spin);
imView.startAnimation(an);
}
private void stopAnimation()
{
;//there is no any stop function!
}
}
also, in res/anim I put spin.xml that is my animation
<?xml version="1.0" encoding="utf-8"?>
<set>
<rotate
android:fromDegrees="0"
android:toDegrees="-18000"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50000" />
</set>
Upvotes: 0
Views: 1393
Reputation: 134664
EDIT: I see. Okay, try the clearAnimation()
method associated with the View
class. You can call it directly on your ImageView
, I'm almost certain this should work for your case:
imView.clearAnimation();
What have you tried? AnimationDrawable
has a stop()
method. You need to post how you're creating/starting the animation.
Upvotes: 2