【问题标题】:How do Android applications receive input from touch screen?Android 应用程序如何接收来自触摸屏的输入?
【发布时间】:2016-01-08 06:50:20
【问题描述】:

我想知道应用程序如何处理来自触摸屏的输入。例如,如果用户触摸坐标 x,y,打开的(在前台处于活动状态)应用程序如何知道必须现在单击坐标 x,y 处的小工具(例如按钮)?

另外,我可以控制应用使用其他应用处理触摸输入的方式吗?我的意思是,我想构建一个使用services 来控制其他应用程序如何处理其输入的应用程序,当然这需要我的应用程序具有permission 才能访问其他应用程序设置,但我的问题是,这可能吗?

我搜索了应用程序如何处理触摸输入,我发现这些结果很有用,但与我的情况无关,

http://developer.android.com/training/gestures/index.html

How does Android device handle touch screen input?

另外,我知道在 Android 中任何输入硬件都由HAL (Hardware Abstraction Layer) 控制,而且每个输入设备都有自己的驱动程序。但是应用程序如何处理来自这些设备的输入?

谢谢。

【问题讨论】:

    标签: android input touch android-service android-permissions


    【解决方案1】:

    在 Android 中有几种处理触摸的方法。

    首先使用 Buttons 你可以设置一个onClick() 方法,当你触摸屏幕时会自动触发。

    另一种选择是将onTouchlistener 附加到您的活动中。

    在这个例子中,一个名为“Example”、ID 为“exampleid”的自定义视图类被附加到一个“onTouchListener

     Public class Example extends View implements View.onTouchListener {
    
    public Example(Context context) {
    Example exampleView = (Example) findViewById(R.id.exampleid); //This is how you set up a onTouch Listener.
        gameView.setOnTouchListener(this);
    }
    
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    
    //Do something when touched.
    }
    
    }
    

    【讨论】:

    • 谢谢。但是,我想你误解了我的问题。我不是指我们如何使用一些代码来处理它。相反,我问的是如何在操作系统和硬件级别发生这种情况。不管怎样,你的回答还是有用的,谢谢。
    猜你喜欢
    • 2015-06-28
    • 1970-01-01
    • 2020-06-29
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多