2012-11-25 81 views
0

我打算將觸摸事件從父視圖轉移到其子視圖。我嘗試了一些構造,但到目前爲止,我還沒有成功地將觸摸處理分配給另一個視圖,但僅將觸摸處理從父視圖委派給子視圖,這不完全相同。從父視圖更改觸摸處理

這就是我想實現:

The green dot is a Touch Down Event on the parent, then I am dragging towards another view, which is than picked up on the blue spot (fireing Touch Down on the child viee) and from this point the parent view is not involved anymore.

綠點是對父向下觸摸事件,然後我拖向另一種觀點認爲,這是不是在藍斑回升(在子視圖上觸發Touch-Down),並且從這一點開始,父視圖不再涉及,就像我首先觸摸孩子一樣。

我可以通過擴展父項onTouchEvent方法來委託觸摸事件,然後在進入childs視圖邊界時調用child.dispatchTouchEvent(),但我想避免父母參與。

回答

0

View.OnTouchListener文檔,一個OnTouch的回報()是:

返回

True if the listener has consumed the event, false otherwise. 

基本上,如果你希望父向onTouchListener反應,返回false。如果你不想反應,返回true。

+0

這是真的,但是當我返回false(而ACTION-MOVE分離時),觸摸事件不會傳播到任何子視圖。 – joecks