I'm trying to implement pinch zooming functionality on my custom view in my Android application. I have use following class to do it.
public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
public ScaleGestureDetector mScaleDetector;
public float mScaleFactor = 1.f;
public ScaleListener(){
}
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));
invalidate(); //Error
return true;
}
}
I want to call invalidate()
method as above within onScale
but it's wrong because this is outside from my custom view. However I try to do it by instantiating a custom view here as follows.
View myview = new DrawingView();
myview.invalidate();
But this one also returns an error. Can't instantiate my custom view. So how to call invalidate() method here?