android - How do I reverse a running animation? -
when button
touched, starts zoom animation.
animation zoomin = animationutils.loadanimation(context, r.anim.zoomin); view.startanimation(zoomin);
the zoomin.xml code:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillenabled="true" android:fillafter="true"> <scale android:fromxscale="1.0" android:toxscale="1.3" android:fromyscale="1.0" android:toyscale="1.3" android:pivotx="50%" android:pivoty="50%" android:duration="200" android:interpolator="@android:anim/accelerate_interpolator"/> </set>
but if button
released during still running animation, should reverse animation this point in time.
how can achieve that?
you use viewpropertyanimator
achieve this.
for example:
button button = (button) findviewbyid(r.id.yourbutton); button.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { // adjust scale , duration values according needs if (event.getaction() == motionevent.action_down) { v.animate().scalex(2).scaley(2).setduration(2000); } else if (event.getaction() == motionevent.action_up) { v.animate().scalex(1).scaley(1).setduration(2000); } return false; } });
Comments
Post a Comment