2014-10-09 53 views
0

當我使用縮放縮放手勢時,以水平方式,當按下的座標和釋放的座標達到一定的差值時,滑動功能總是被調用。如何在不調用webview中的滑動功能的情況下使用縮放縮放?

我該如何解決這個問題?

這是對的WebView

view.getSettings().setBuiltInZoomControls(true); 
    view.getSettings().setSupportZoom(true); 
    view.getSettings().setDisplayZoomControls(false); 

的刷卡功能

protected void swipePage(View v, MotionEvent event, int book) { 
    int action = MotionEventCompat.getActionMasked(event); 

    switch (action) { 
    case (MotionEvent.ACTION_DOWN): 
     swipeOriginX = event.getX(); 
     swipeOriginY = event.getY(); 
     break; 

    case (MotionEvent.ACTION_UP): 
     int quarterWidth = (int) (screenWidth * 0.3); 
     float diffX = swipeOriginX - event.getX(); 
     float diffY = swipeOriginY - event.getY(); 
     float absDiffX = Math.abs(diffX); 
     float absDiffY = Math.abs(diffY); 

     if ((diffX > quarterWidth) && (absDiffX > absDiffY)) { 
      try { 
       navigator.goToNextChapter(index); 
      } catch (Exception e) { 
       errorMessage(getString(R.string.error_cannotTurnPage)); 
      } 
     } else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) { 
      try { 
       navigator.goToPrevChapter(index); 
      } catch (Exception e) { 
       errorMessage(getString(R.string.error_cannotTurnPage)); 
      } 
     } 
     break; 
    } 
} 

回答

0

檢查,如果這項工作的設置 - 如果要是單個手指觸摸會有那麼只有做刷卡條件檢查放。將「事件」變量更改爲本地變量。

if(event.getPointerCount() == 1) 
    { 
    switch (action) { 
    case (MotionEvent.ACTION_DOWN): 
      swipeOriginX = event.getX(); 
      swipeOriginY = event.getY(); 
      break; 

    case (MotionEvent.ACTION_UP): 

    int quarterWidth = (int) (screenWidth * 0.3); 
    float diffX = swipeOriginX - event.getX(); 
    float diffY = swipeOriginY - event.getY(); 
    float absDiffX = Math.abs(diffX); 
    float absDiffY = Math.abs(diffY); 

    if ((diffX > quarterWidth) && (absDiffX > absDiffY)) { 
     x = 1; 
     try { 
      navigator.goToNextChapter(index); 
      x = 0; 
     } catch (Exception e) { 
      x = 1; 
      errorMessage(getString(R.string.error_cannotTurnPage)); 
     } 
    } else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) { 
     x = 1; 
     try { 
      navigator.goToPrevChapter(index); 
      x = 0; 
     } catch (Exception e) { 
      x = 1; 
      errorMessage(getString(R.string.error_cannotTurnPage)); 
     } 


    break;  
    } 
    } 
} 
else if(event.getPointerCount()==2) 
{ 
    // code for pinch zoom 
} 
+0

它不工作..我使用內置的代碼爲WebView捏縮放。我在我的WebView的設置中啓用了縮放縮放功能。 – Cedu 2014-10-13 08:02:24

相關問題