Android canvas scale ondraw - imageview not scaled -


the question: how resize custom imageview canvas resized through canvas.scale() within ondraw() method?

i have problem implementing pinch zoom custom imageview. using example android developer site:

private scalegesturedetector mscaledetector; private float mscalefactor = 1.f;  public mycustomview(context mcontext){     ...     // view code goes here     ...     mscaledetector = new scalegesturedetector(context, new scalelistener()); }  @override public boolean ontouchevent(motionevent ev) {     // let scalegesturedetector inspect events.     mscaledetector.ontouchevent(ev);     return true; }  @override public void ondraw(canvas canvas) {     super.ondraw(canvas);      canvas.save();     canvas.scale(mscalefactor, mscalefactor);     ...     // ondraw() code goes here     ...     canvas.restore(); }  private class scalelistener         extends scalegesturedetector.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;     } } 

the problem here is: canvas.scale(mscalefactor, mscalefactor) resizes canvas, containing imageview not resized accordingly. example, if image enlarged, looks clipped. image within image zoomed in , out, imageview not.

i tried replace cavnas.scale() following code,

setscalex (mscalefactor); setscaley (mscalefactor); 

this code zoom whole view. problem method is, not smooth , flickers.

i have looked @ existing libraries, don't them complex , adding zoom feature, 1 needs include whole bunch of classes , interfaces. have imageview supports 2 features: pan , zoom , start simple method, if possible, instead of using libraries.

i have looked @ many stackoverflow posts regarding implementation of zoom feature imageviews, or custom views in general. no solution worked properly.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -