onTouchEvent()只适用于空格?

时间:2012-04-03 18:11:14

标签: java android onclick ontouchevent

我相信很多其他人在过去的某个地方会遇到这个问题。

我的main.xml分为9 LinearLayouts,权重为1,weightsum当然为9。 1个布局用空格填充。

我的活动中有一个onTouchEvent()函数,它的工作非常精细。问题是触摸仅在空布局中被识别。其他布局充满了按钮,edittexts和textview。但触摸事件在那里不起作用。我认为在调用onTouchEvent()之前调用按钮的'onClick'。

有什么方法可以让整个屏幕都能触摸?

我没有提供任何代码,因为它是一个普遍的问题,根据我不需要任何代码。 在期待中感谢你。

1 个答案:

答案 0 :(得分: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 ()方法在屏幕上的任何位置发生任何触摸事件时调用。