SimpleOnScaleGestureListener仅接收onScaleBegin事件

时间:2011-10-07 16:02:53

标签: android

我正在尝试实现一个onscalegesturelistener。 我的问题是,SimpleOnScaleGestureListener只接收onScaleBegin事件。 其他事件没有报道。我正在使用Nexus One进行测试

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());
}

}

在我正在做的活动中:

....

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

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

非常感谢

1 个答案:

答案 0 :(得分:16)

onScaleBegin()和onScale()的返回值控制是否继续序列。如果onScaleBegin()返回false,就像你的那样,其他任何一个都不会运行。