android translate animation clips the part of view not shown on screen -
i have relative layout containing textviews floats on gridview. when select item in grid, layout moves down end of screen , 1/5th of visible. done using simple translate animation. when click button in grid, need relative layout move original position on top of gridview. did translate animation , happnening, portion of relativelayout visible when collapsed translating (moving) , other portion becomes visible after animation has ended. looks ugly.
i know android doesnt draw portion of view not visible on screen. there way force draw full portion ?
my animation code given below:
public void smoothexpanderanimate(final int finaltarget,final relativelayout expander,final int animatetoy,final boolean setexpanded,final boolean refreshgrid) { final relativelayout.layoutparams head_params = (relativelayout.layoutparams)expander.getlayoutparams(); translateanimation anim = new translateanimation(0f, 0f, 0f, animatetoy); anim.setduration(400); //timelistheight = list.getheight(); //anim.setfillafter(true); anim.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) { //should try here ? } @override public void onanimationrepeat(animation animation) { } @override public void onanimationend(animation animation) { head_params.topmargin = finaltarget; expander.clearanimation(); expander.setlayoutparams(head_params); isexpanded = setexpanded; isanimating = false; if(!setexpanded) { setchildheight(timelistheight, list); } } }); isanimating = true; expander.startanimation(anim); }
i found solution this.
if dont need support lower api levels , fine api level 11 onwards, can use objectanimator this. objectanimator has translatey method works quite well.
if need support api 8 onwards, need make sure view comes within bounds of screen , animates. following code modification did trick.
i know seems weird, let me know if there better way this.
public void smoothexpanderanimate(boolean addspecialfix,final int finaltarget,final relativelayout expander,final int animatetoy,final boolean setexpanded,final boolean refreshgrid) { final relativelayout.layoutparams head_params = (relativelayout.layoutparams)expander.getlayoutparams(); translateanimation anim = new translateanimation(0f, 0f, 0f, animatetoy); anim.setduration(400); expander.setvisibility(view.invisible); //make view invisible if(isexpanded && addspecialfix){ //this fix int old = head_params.topmargin; head_params.topmargin = finaltarget; expander.clearanimation(); expander.setlayoutparams(head_params); //move invisible view final position anim = new translateanimation(0f, 0f, old-closedy, 0); log.d("asdasd", old+""); anim.setduration(400); } //timelistheight = list.getheight(); //anim.setfillafter(true); anim.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationrepeat(animation animation) { } @override public void onanimationend(animation animation) { head_params.topmargin = finaltarget; expander.clearanimation(); expander.setlayoutparams(head_params); isexpanded = setexpanded; isanimating = false; expander.setvisibility(view.visible); if(refreshgrid) { mcaladapter.notifydatasetchanged(); } if(!setexpanded) { setlistheight(timelistheight, list); } } }); isanimating = true; expander.startanimation(anim); }
Comments
Post a Comment