android - How to zoom ViewGroup? -
i need create view user can scale. list of components show in view pager. cant scaling in activity. that
s why created custom view extends relativelayout.
public class jsonrelativelayout extends relativelayout { private scalegesturedetector mscaledetector; private float mscalefactor = 1.f; public jsonrelativelayout(context context) { super(context); mscaledetector = new scalegesturedetector(context, new scalelistener()); } public jsonrelativelayout(context context, attributeset attrs) { super(context, attrs); mscaledetector = new scalegesturedetector(context, new scalelistener()); } public jsonrelativelayout(context context, attributeset attrs, int defstyleattr) { super(context, attrs, defstyleattr); mscaledetector = new scalegesturedetector(context, new scalelistener()); } @override public boolean ontouchevent(motionevent event) { mscaledetector.ontouchevent(event); return true; } @override public void ondraw(canvas canvas) { super.ondraw(canvas); canvas.save(); canvas.scale(mscalefactor, mscalefactor); //... //your ondraw() code //... canvas.restore(); } private class scalelistener extends simpleonscalegesturelistener { @override public boolean onscale(scalegesturedetector detector) { mscalefactor *= detector.getscalefactor(); // don't let object small or large. mscalefactor = math.max(0.1f, math.min(mscalefactor, 5.0f)); invalidate(); return true; } }
but method onscale not work. , don`t know why.
to zoom view group need extend scrollview , override dispatchtouchevent , dispatchdraw.
Comments
Post a Comment