简体   繁体   English

Android:当另一个手指已经触摸屏幕时,是否可以处理点击?

[英]Android: Is it possible to handle a click while another finger is already touching the screen?

I'm a beginner in Android development and I'm developing an app for little kids. 我是Android开发的初学者,我正在为小孩子开发一款应用程序。 As you know kids tend to hold the screen with one hand (where it touchs the screen already) and click the screen with another hand. 如你所知,孩子们倾向于用一只手握住屏幕(它已经触摸屏幕)并用另一只手点击屏幕。 Unfortunately, this renders the screen unresponsive to the clicks. 不幸的是,这会使屏幕无法响应点击次数。 My question is, is there a way to make the screen respond to a click even if it is already touched with one finger? 我的问题是,有没有办法让屏幕响应一次点击,即使它已被一根手指触摸?

There is, by handling in your onTouchEvent() the MotionEvent ACTION_POINTER_DOWN . 还有就是,在你处理onTouchEvent()MotionEvent ACTION_POINTER_DOWN Imagine you want to show a Toast when more than one finger is touching the screen; 想象一下,当多个手指触摸屏幕时,您想要显示Toast ; you could do it like this: 你可以这样做:

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
        Toast.makeText(this, "More than one finger on screen", Toast.LENGTH_SHORT);
    }
}

You can check the multi-touch Android developer's page for more info on the subject. 您可以查看多点触控Android开发人员页面 ,了解有关该主题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM