2015-10-04 26 views
2

我有WebView和其他視圖背後/下。WebView如何通過觸摸背後,但只在特定區域

如何在WebView上控制觸摸並將其傳遞給其他視圖,但只有這些來自WebView的特定區域?

是否有可能捕獲事件和其他功能的功能,您可以在其他視圖上觸發這些事件?

回答

0

此代碼的伎倆:

sourceView.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     MotionEvent motionEvent = MotionEvent.obtain(event); 

     //these 3 lines is for bug when target and source has different on screen positions 
     sourceView.getLocationOnScreen(posTemp1); 
     targetView.getLocationOnScreen(posTemp2); 
     motionEvent.offsetLocation(posTemp1[0]-posTemp2[0], posTemp1[1]-posTemp2[1]); 

     targetView.dispatchTouchEvent(motionEvent); 
     return false; //true if we want sourceView to not handle it 
    } 
}); 

我不包括檢測特定區域,但它的motionEvent的getX()和的getY()的簡單,你只測試結果;