使用 android 游戏手柄操纵杆时如何监听开关 MotionEvent.AXIS?

Posted

技术标签:

【中文标题】使用 android 游戏手柄操纵杆时如何监听开关 MotionEvent.AXIS?【英文标题】:How to listen switch MotionEvent.AXIS when an android gamepad joystick is useing? 【发布时间】:2016-11-11 06:05:50 【问题描述】:

我尝试在 View 中聆听 android 游戏手柄的操纵杆 MotionEvent

当我使用public boolean onGenericMotionEvent(MotionEvent event) 时,我不知道我应该在方法event.getAxisValue(MotionEvent.AXIS_XXXXXX) 中使用哪个MotionEvent.AXIS

例如:

左摇杆:

event.getAxisValue(MotionEvent.AXIS_X),event.getAxisValue(MotionEvent.AXIS_Y)

右摇杆:

event.getAxisValue(MotionEvent.AXIS_Z),event.getAxisValue(MotionEvent.AXIS_RZ)

但我不知道该使用哪个(MotionEvent.AXIS_XMotionEvent.AXIS_Z)?

是否有一些API可以选择MotionEvent

【问题讨论】:

【参考方案1】:

只需使用所有类型的event.getAxisValue,并判断值!=0

【讨论】:

以上是关于使用 android 游戏手柄操纵杆时如何监听开关 MotionEvent.AXIS?的主要内容,如果未能解决你的问题,请参考以下文章