如何检测在机器人触摸事件 [英] How to detect touch events in Android

查看:144
本文介绍了如何检测在机器人触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以检测活动的所有触摸事件,并捕捉到它,然后在回传球的事件传递到另一个视图?

Is it possible to detect all touch events in an Activity and capture it and then in return pass that pass event to another View?

例如:

按钮1和按钮2。当按钮1 pressed我希望捕获的触摸/点击事件,并自动传递触摸事件到按钮2,基本上有一个触摸/ preSS你所产生的点击并且同样点击被传递到自动的第二个按钮。

Button 1 and Button 2. When Button 1 is pressed I want to capture that touch/click event and automatically pass that touch event to Button 2, basically with one touch/press you get the click generated and that same click is passed on to the second button automatically.

推荐答案

拿来看这个API说明第一。

take look this API description first.

布尔   android.app.Activity.dispatchTouchEvent(MotionEvent   EV)

boolean android.app.Activity.dispatchTouchEvent(MotionEvent ev)

公共布​​尔dispatchTouchEvent   (MotionEvent EV)自:API级别1   调用来处理触摸屏事件。   您可以覆盖这个拦截所有   触摸屏事件,他们是前   调度到该窗口。务必   称这种实现触摸   那应该如何处理屏事件   正常。

public boolean dispatchTouchEvent (MotionEvent ev) Since: API Level 1 Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

参数EV触摸屏事件。

返回Boolean如果返回true   事件被消耗。

Returns boolean Return true if this event was consumed.

正如你所看到的,你可以拦截所有的触摸事件。

As you can see, you can intercept all touch events.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    super.dispatchTouchEvent(ev);
    if(btn1.onTouchEvent(ev)){
        return btn2.onTouchEvent(ev);
    }else{
        return false;
    }
}

这些codeS是你在找什么,我认为。

These codes are what you are looking I think.

这篇关于如何检测在机器人触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆