onResize事件在我抬起其中一根手指之前结束

时间:2016-09-27 09:40:24

标签: android resize gesture

我正在使用以下代码来处理android上的resize(pinch)事件:

//my custom framelayout supporting resize functionality
ScalingFrameLayout pieceContainer=(ScalingFrameLayout)fragment.getView().findViewById(R.id.pieceContainer);
//set onResize handler
setScaleListener(pieceContainer.getContext());
//tonnel touch events to gesture detector
pieceContainer.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mScaleDetector.onTouchEvent(event);
            return true;
        }
    });
...
//somewhere in the class
private ScaleGestureDetector mScaleDetector;
//
private void setScaleListener(Context context) {
mScaleDetector= new ScaleGestureDetector(context, new ScaleGestureDetector.OnScaleGestureListener() {
        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            Log.d("onScaleEnd", "end");
        }
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            Log.d("onScaleBegin", "begin");
            return true;
        }
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            Log.d("onScale", "zoom ongoing, scale: " + detector.getScaleFactor());
            return false;
        }
    });
}

问题在于,当我执行放大手势时(例如),此代码调用onScaleBegin,然后调用5-6次onScale,最后调用onScaleEnd。虽然我没有从屏幕上抬起任何手指。是否有办法阻止ScaleGestureDetector调用onScaleEnd并让它继续跟踪我的缩放手势,直到我释放屏幕?

1 个答案:

答案 0 :(得分:0)

通过在f​​rameLayout的基础上实现自定义双向scrollview来解决该问题。