android - Keep animated View at final Animation Position -
so i'm animating view using animation:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="1000" android:fromydelta="0%" android:toydelta="-75%" /> </set> it visually want want freeze result of animation. need somehow resulting layout parameters (or else?) after animation , set layout. assume layout y-coord changing 0 100 don't know starting coords , resulting coords. need resulting coords , set layout cuz if wouldn't layout returns initial position after animation need make stay in new position instead of returning back. need 2.3.x compatible solution.
update 1
tried nineoldandroids:
objectanimator.offloat(rootwrapper, "translationy", -rootwrapper.getheight()*75/100).start(); this animates view , view stays @ animated position - thats want achieve.
controls stays @ positions virtually. thou layout visible 25% of bottom part , 75% of rest screen looks empty if tap empty screen area button's (which there b4 animation) onclick triggered. same happens xml-animtaions if set
animation.setfillafter(true); how fix issue? controls has move view.
update 2
code:
public void showabout(){ final animation animshow = animationutils.loadanimation(this, r.anim.about_in_from_bottom); animshow.setfillafter(true); //objectanimator.offloat(rootwrapper, "translationy", -rootwrapper.getheight()*75/100).start(); animshow.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationrepeat(animation animation) {} @override public void onanimationend(animation animation) { linearlayout.layoutparams rootlp = (linearlayout.layoutparams) rootwrapper.getlayoutparams(); log.i(this,"rootlp: h: "+rootlp.topmargin+ " / w: "+rootlp.bottommargin); rootlp.topmargin = -rootlp.height*75/100; rootwrapper.setlayoutparams(rootlp); } }); rootwrapper.startanimation(animshow); } i got problem - rootlp.height returns 0 cuz match_parent or like. wont return real pixels value representing constant! looks have 2 play .getviewtreeobserver().addongloballayoutlistener.
ok, got real height of rootwrapper via getviewtreeobserver(). , using formula rootlp.topmargin = -rootlp.height*75/100; i'm getting more issues.
1) after animation view moves additionally (due setting lp).
2) controls animated view contains (buttons has move parent view) stays @ positions virtually (they invisible clickable)! visually controls moved animated view , can't reach (it goes off screen). if tap area before animation corresponding onclick() triggers! fun!
update 3
had achieved goal! problem moving view's child containers. thinking if move view of child views moving. thats not case , had move child views manually after animation completes fix ghost buttons.
please consider setfillafter(boolean); setting true make view stay @ animated position.
animation anim = new translateanimation(0, 0, 0, 100); // or animation anim = animationutils.loadanimation(this, r.anim.animation_name); anim.setfillafter(true); anim.setduration(1000); this can done easier using viewpropertyanimator, available api 14 , onwards:
int animationpos = 500; view.animate().y(animationpos).setduration(1000); // keep view @ animated position or consider animationlistener layoutparams after animation:
anim.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) {} @override public void onanimationrepeat(animation animation) {} @override public void onanimationend(animation animation) { // layoutparams here , set in example views // parent relative layout, please change desires relativelayout.layoutparams lp = (relativelayout.layoutparams) view.getlayoutparams(); lp.topmargin = yournewtopmargin // use topmargin y-property, left margin x-property of view view.setlayoutparams(lp); } }); view.startanimation(anim); update:
how know how many pixels view moved, depending on percentage values of animation?
the percentage value in .xml animation relative animated view's dimensions (such width , height). therefore, need use your view's width , height properties (depending on weather u use x or y animation actual animation distance in pixels).
for example:
your view has width of 400 pixels. animation animates x-property 0% 75%, meaning view move 300 pixels (400 * 0.75) right side. onanimationend(), set layoutparams.leftmargin 300 , view have desired position.
Comments
Post a Comment