animation - Animate change width of android RelativeLayout -
i need change width of relativelayout 0 600px programmatically, in animated way. i'm using following code:
animation = new animation() { @override protected void applytransformation(float interpolatedtime, transformation t) { relativelayout.layoutparams drawerparams = (layoutparams) drawer.getlayoutparams(); drawerparams.width = 600; drawer.setlayoutparams(drawerparams); } }; a.setduration(1000); //animate 1s layout.startanimation(a);
however, reason isn't working. can point me in right direction?
i typed , works perfect here
animation
public class resizewidthanimation extends animation { private int mwidth; private int mstartwidth; private view mview; public resizewidthanimation(view view, int width) { mview = view; mwidth = width; mstartwidth = view.getwidth(); } @override protected void applytransformation(float interpolatedtime, transformation t) { int newwidth = mstartwidth + (int) ((mwidth - mstartwidth) * interpolatedtime); mview.getlayoutparams().width = newwidth; mview.requestlayout(); } @override public void initialize(int width, int height, int parentwidth, int parentheight) { super.initialize(width, height, parentwidth, parentheight); } @override public boolean willchangebounds() { return true; } }
usage
if(animate) { resizewidthanimation anim = new resizewidthanimation(leftframe, leftfragmentwidthpx); anim.setduration(500); leftframe.startanimation(anim); } else { this.leftfragmentwidthpx = leftfragmentwidthpx; layoutparams lp = (layoutparams) leftframe.getlayoutparams(); lp.width = leftfragmentwidthpx; leftframe.setlayoutparams(lp); }
Comments
Post a Comment