Saturday, 10 August 2013

Text being Clipped while zooming

Text being Clipped while zooming

Hello friends I am making an application in which i am applying pinch in
zoom on the text written on canvas.Everything is working fine but while
zooming when text goes out of the screen it does not scroll horizontally
as well as vertically,I mean to say that the text which is on screen would
be show, the text went out of the screen while zooming is not visible.
Here is my code. Any help would be appreciable.
private static class SampleView extends View {
public ScaleGestureDetector mScale;
public float mScaleFactor = 1.0f;
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
mScale = new ScaleGestureDetector(context, new ScaleListener());
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.scale(mScaleFactor, mScaleFactor);
Paint paint = new Paint();
canvas.drawText("Hello Friends how are you", 30, 40, paint);
canvas.restore();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mScale.onTouchEvent(event);
return true;
}
private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
mScaleFactor = Math.max(.1f, Math.min(mScaleFactor, 5.0f));
invalidate();
return true;
}
}
}

No comments:

Post a Comment