animation - Move and scale custom view in android -
animation - Move and scale custom view in android -
i want create custom menu android application iphone's https://github.com/xavierdk/xdkairmenu . application shows menu on left side of screen , content on right side of screen.
this custom layout right side of screen(content view)
public boolean ontouchevent(motionevent event) { gesturedetector.ontouchevent(event); if (istranformed) { final int x = (int) event.getrawx(); final int y = (int) event.getrawy(); switch (event.getaction()) { case motionevent.action_move: framelayout.layoutparams layoutparams = (framelayout.layoutparams) .getlayoutparams(); if (layoutparams.leftmargin == 0 && layoutparams.topmargin == 0) { //requestlayout(); istranformed = false; isscrolling = false; break; } isscrolling = true; int xdiff = layoutparams.leftmargin - (x - _xdelta); layoutparams.leftmargin = x - _xdelta; int scalefactor = layoutparams.leftmargin > 0 ? layoutparams.leftmargin : 1; layoutparams.topmargin = layoutparams.topmargin - ((layoutparams.topmargin / scalefactor) * xdiff); if (layoutparams.leftmargin < 0) { layoutparams.leftmargin = 0; } if (layoutparams.topmargin < 0) { layoutparams.topmargin = 0; } layoutparams.width = (displaymetrics.widthpixels - layoutparams.leftmargin); layoutparams.height = (displaymetrics.heightpixels - (layoutparams.topmargin * 2)); this.setlayoutparams(layoutparams); //invalidate(); //setleft(layoutparams.leftmargin); //settop(layoutparams.topmargin); /* this.setx(layoutparams.leftmargin); this.sety(layoutparams.topmargin);*/ this.requestlayout(); break; case motionevent.action_up: if (isscrolling) { framelayout.layoutparams params = (framelayout.layoutparams) customslidinglayout.this .getlayoutparams(); if (params.leftmargin < displaymetrics.widthpixels / 2) { if (!isanimating) { isanimating = true; resizemoveanimation anim = new resizemoveanimation( this, 0, 0, displaymetrics.widthpixels, displaymetrics.heightpixels); anim.setanimationlistener(animationlistener); startanimation(anim); } } else { if (!isanimating) { isanimating = true; rect rect = new rect(); getlocalvisiblerect(rect); resizemoveanimation anim = new resizemoveanimation( this, (int) (displaymetrics.widthpixels * 0.8), displaymetrics.heightpixels / 4, displaymetrics.widthpixels * 2, (int) (displaymetrics.heightpixels * 0.75)); // anim.setanimationlistener(animationlistener); startanimation(anim); isanimating = false; } } isscrolling = false; } break; case motionevent.action_down: framelayout.layoutparams lparams = (framelayout.layoutparams) .getlayoutparams(); _xdelta = x - lparams.leftmargin; break; } homecoming true; } homecoming false; } } view on right side(content view) resize little size when click on menu button.and resize original size when touch on resized view.also, want scale , move view right-to left on touch. above code snippet have view position issues. not update view layout/position correctly.how can prepare it?
use code accomplish scaling , transition animation
float scalefactor = 0.5; float translatex = 500; // translate amount view.animate().scalex(scalefactor).translationxby(translatex).start(); for reverse animation
view.animate().scalex(1).translationxby(-translatex).start(); android animation scale move ontouchlistener
Comments
Post a Comment