android - Translate animation created programmatically has incorrect duration and offset -
here's needs done:
i have top bar 3 buttons. 2 on right can pressed , nothing interesting them. left 1 replaces 3 buttons other three. animation: middle , right (new ones) buttons slide out left button's position corresponding places, while old buttons fade out. left button gets replaced without movement: old 1 fades out, new 1 fades in.
how done:
final animation fadeout, fadein; animation fadeoutwithlistener; fadein = animationutils.loadanimation(this, r.anim.camera_top_bar_fade_in); fadeout = animationutils.loadanimation(this, r.anim.camera_top_bar_fade_out); final translateanimation slideanim; slideanim = new translateanimation( animation.relative_to_parent, -flashautobtn.getleft(), animation.relative_to_self, 0, animation.relative_to_self, 0, animation.relative_to_self, 0); slideanim.setduration(1000l); slideanim.setstartoffset(0); fadeoutwithlistener = animationutils.loadanimation(this, r.anim.camera_top_bar_fade_out); fadeoutwithlistener.setanimationlistener(new animation.animationlistener() { @override public void onanimationstart(animation animation) { flashautobtn.startanimation(fadein); flashonbtn.startanimation(slideanim); flashoffbtn.startanimation(slideanim); } @override public void onanimationend(animation animation) { flashbtn.setvisibility(view.invisible); gridbtn.setvisibility(view.invisible); switchcamerasidebtn.setvisibility(view.invisible); flashautobtn.setvisibility(view.visible); flashoffbtn.setvisibility(view.visible); flashonbtn.setvisibility(view.visible); } @override public void onanimationrepeat(animation animation) { } }); flashbtn.startanimation(fadeoutwithlistener); gridbtn.startanimation(fadeout); switchcamerasidebtn.startanimation(fadeout);
how works: fadein/out animations ok - defined in xml, have duration set 1000 , last 1 second. no offset.
two translation animations work incorrectly: first, don't start @ same time fadeoutwithlistener animation. instead, wait 100 or 200 ms (with duration of 100 or 200 ms) flash transformation (coordinates correct btw) , disappear. after fadeoutwithlistener done - listener's onanimationend fires , buttons become visible.
this final try - before did without listener - consecutive calls of startanimation , setvisibility - same identical behavior.
if apply 2 animation same ui @ same time, remember, latest 1 performed.
to make multiple animation @ same time, need use animationset
animationset set = new animationset(false); set.addanimation(fadeout); set.addanimation(slideout); view.setanimation(set); set.start();
Comments
Post a Comment