2012-04-03 85 views
0

我相信很多其他人在過去的某個地方會遇到這個問題。onTouchEvent()僅適用於空白空間?

我的main.xml被分爲9 LinearLayouts與權重1和weightsum是9當然。 1佈局充滿空白空間。

我在我的活動中有一個onTouchEvent()函數,它的工作原理非常好。問題是觸摸僅在空佈局中被識別。其他佈局充滿了按鈕和編輯文本和文字瀏覽。但觸摸事件不起作用。我認爲在調用onTouchEvent()之前調用按鈕的「onClick」。

有什麼辦法可以使整個屏幕上的觸摸工作?

我還沒有提供任何代碼,因爲它是一個普通的問題,根據我不需要任何代碼。 感謝您的期待。

回答

0

因爲Activity doc說:當任何觸摸事件發生在屏幕上的任何地方稱爲

onTouchEvent (MotionEvent event) Called when a touch screen event was not handled by any of the views under it. 
This is most useful to process touch events that happen outside of your window bounds, 
    where there is no view to receive it. 

onUserInteraction()方法。