2016-09-27 66 views
0

我用下面的代碼來處理在Android resize(pinch)事件:在onResize事件完成之前我舉起一個手指

//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,並讓它保持跟蹤我的縮放手勢,直到我釋放屏幕?

+0

更新:進一步調查顯示ScaleGestureDetector與Horizo​​ntalScrollView衝突,它是我的pieceContainer.I的父級,因爲我需要雙向滾動,所以使用了兩個嵌套滾動視圖。我想知道是否有本地組件可以做到這一點? –

回答

0

該問題通過在frameLayout的基礎上實現自定義雙向滾動視圖來解決。

相關問題