Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleOnScaleGestureListener only receives onScaleBegin event

Tags:

android

I'm trying to implement an onscalegesturelistener. My problem is, that the SimpleOnScaleGestureListener only receives the onScaleBegin event. The other events aren't being reported. I'm using a Nexus One for testing

public class ZoomHandler extends SimpleOnScaleGestureListener {

public float zoom;

public ZoomHandler(float zm) {
    this.zoom = zm;
}

public boolean onScale(ScaleGestureDetector arg0) {
    Log.i("SCALE", "onscale " + arg0.getScaleFactor());
    this.zoom *= arg0.getScaleFactor();

    // Don't let the object get too small or too large.
    this.zoom = Math.max(0.1f, Math.min(this.zoom, 5.0f));

    return true;
}

@Override
public boolean onScaleBegin(ScaleGestureDetector arg0) {
    Log.i("SCALE", "onscalebegin " + arg0.getScaleFactor());
    return false;
}

@Override
public void onScaleEnd(ScaleGestureDetector arg0) {
    Log.i("SCALE", "onscaleend " + arg0.getScaleFactor());
}

}

In the activity I'm doing this:

....

mScaleDetector = new ScaleGestureDetector(this , new ZoomHandler(this.zoom));

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.mScaleDetector.onTouchEvent(event);
    .....
}
....

Thanks a lot

like image 566
Simbi Avatar asked Dec 03 '22 06:12

Simbi


1 Answers

The return values of onScaleBegin() and onScale() control whether or not to continue with the sequence. If onScaleBegin() returns false, as yours does, none of the others will run.

like image 117
Withad Avatar answered Jan 25 '23 23:01

Withad