android - Floating Action Button animation Issue -
i playing around fab in support design library when ran inti issue. replaced oncreate method in default blank activity template in android studio, looks like:
import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.view; import android.view.animation.translateanimation; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); final floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { translateanimation anim = new translateanimation(0, -500, 0, -500); anim.setduration(1000); anim.setfillenabled(true); anim.setfillafter(true); fab.startanimation(anim); } }); fab.setonlongclicklistener(new view.onlongclicklistener() { @override public boolean onlongclick(view view) { translateanimation anim = new translateanimation(0, -500, 0, -500); anim.setduration(1000); anim.setfillenabled(true); anim.setfillafter(true); fab.startanimation(anim); return true; } }); } }
so basically, added onclicklistener , onlongclicklistener translate fab 500idks, problem doesn't work it's supposed to.
when click on nothing happens, weird start with. here's video of happening.
when longpress on it, animates should, if keep pressing, , whenever lift finger goes original position regardless of whether animation complete or not though set setfillenabled(true)
, setfillafter(true)
.
here videos of happens when lift finger , when leave finger on screen till end , everything.
why happening?
i don't know why animation issue, looks bug. checked code , works on android 6.0, doesn't work on android emulator android 4.4 on board (but issue little bit different yours).
so assumption it's bug, because translateanimation
had (and maybe still has) bugs one, two.
and suggestion how can avoid next. use viewpropertyanimator
animate views. , code in case should like:
fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { fab.animate() .translationx(-500) .translationy(-500) .setduration(1000) .start(); } }); fab.setonlongclicklistener(new view.onlongclicklistener() { @override public boolean onlongclick(view view) { fab.animate() .translationx(-500) .translationy(-500) .setduration(1000) .start(); return true; } });
i checked on android emulator android 4.3, 4.4, 5.0, 6.0 , works fine.
update
found solution you. can use viewpropertyanimatorcompat
support library , code similar to:
fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { viewcompat.animate(fab) .translationx(-500) .translationy(-500) .setduration(1000) .start(); } }); fab.setonlongclicklistener(new view.onlongclicklistener() { @override public boolean onlongclick(view view) { viewcompat.animate(fab) .translationx(-500) .translationy(-500) .setduration(1000) .start(); return true; } });
Comments
Post a Comment