Simbi
Simbi

Reputation: 1042

SimpleOnScaleGestureListener only receives onScaleBegin event

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

Upvotes: 4

Views: 3320

Answers (1)

Withad
Withad

Reputation: 523

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.

Upvotes: 17

Related Questions