c# - Keep changes after animation, functionality-wise -
so, have scale animation in android project. scaling done when relative layout containing image view clicked , want changes stay.
now, know anim.fillafter = true; , i've managed keep endstate of animation. there's still problem tho. let's have 400x600 px image scale down 200x300 (x,y not changing positions). image scales down when click on on relative layout containing image. after animation on , image seems in 200x300 state. however, can still launch animation clicking in empty space left scaling (that 200 pixels right , 300 px bottom image used fill). best guess that, visually, changes happening , persisting, visually.
code-wise, it's looks like:
ui builder:
customgesturelistener container = new customgesturelistener (this); <- custom relative layout integrating gesturedetector.iongesturelistener, gesturedetector.iondoubletaplistener , scalegesturedetector.ionscalegesturelistener imageview iv = new imageview (this); iv.setimagedrawable (workingcopy); iv.setbackgroundcolor (android.graphics.color.green); iv.clickable = false; container.addview (iv, new viewgroup.layoutparams (viewgroup.layoutparams.fillparent, viewgroup.layoutparams.fillparent)); gesturesextension.click(container).actionevent += delegate(gesturesextension.state statevalue) { ptanimationextender.scale(container, new system.drawing.size(container.width, container.height), new system.drawing.size((int)(container.width / 2), (int)(container.height / 2)), 2, delegate { alertdialog.builder ad = new alertdialog.builder(this); ad.setmessage("view scaled"); ad.create().show(); }); }; the scaling:
public static void scale (this view view, size start, size end, double durationinsec, action callback) { scaleanimation sa = new scaleanimation (((float)start.width) / ((float)view.width), ((float)end.width) / ((float)view.width), ((float)start.height) / ((float)view.height), ((float)end.height) / ((float)view.height)); sa.duration = (long)(durationinsec * 1000); sa.fillafter = true; sa.interpolator = new decelerateinterpolator (2.5f); view.animation = sa; view.animation.animationend += delegate(object sender, animation.animationendeventargs e) { if (callback != null) callback.invoke (); }; view.startanimation (view.animation); } and lastly, onclick listener on customgesturelistener:
public class clickclass { public delegate void event (state statevalue); public event event actionevent; public void callevent(state statevalue) { if (actionevent != null) actionevent (statevalue); } } ///<remarks>detect click on customgesturelistener</remarks> public static clickclass click(this customgesturelistener view) { clickclass click = new clickclass (); view.ontapevent += delegate(state state) { click.callevent (state); }; return click; } something else i've tried replacing fillafter option. on view.animation.animationend event handler had rescaling on view. on these lines:
viewgroup.layoutparams lp = view.layoutparameters; lp.width = end.width; lp.height = end.height; view.layoutparameters = lp; which ended having result wanted! (keeping endstate after rescaling both visually , functionally). issue have changing layout parameter of view when happens view has visual glitch. layout params change executes, fraction of second, entire view rescales smaller version version of before taking correct size.
any solution fixing issue welcomed, either tackling fill after or visual glitch caused change in layoutparams of view... or else have missed
so, ended finding workarround visual flickering when changing layout parameters. stated before, problem solved when applying following on animation end:
viewgroup.layoutparams lp = view.layoutparameters; lp.height = 350; lp.width = 150; view.layoutparameters = lp; the issue visual flicking. visual flicking being caused animationend being called before animation over. so... fixed me: https://stackoverflow.com/a/5110476
Comments
Post a Comment