View.OnGenericMotionEvent(MotionEvent) 方法

定义

实现此方法以处理泛型运动事件。

[Android.Runtime.Register("onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z", "GetOnGenericMotionEvent_Landroid_view_MotionEvent_Handler")]
public virtual bool OnGenericMotionEvent (Android.Views.MotionEvent? e);
[<Android.Runtime.Register("onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z", "GetOnGenericMotionEvent_Landroid_view_MotionEvent_Handler")>]
abstract member OnGenericMotionEvent : Android.Views.MotionEvent -> bool
override this.OnGenericMotionEvent : Android.Views.MotionEvent -> bool

参数

e
MotionEvent

正在处理的泛型运动事件。

返回

如果事件已处理,则为 True;否则为 false。

属性

注解

实现此方法以处理泛型运动事件。

一般运动事件描述游戏杆移动、鼠标或触笔设备的悬停事件、触控板触摸、滚轮运动和由 或 #onTrackballEvent(MotionEvent)未处理#onTouchEvent(MotionEvent)的其他运动事件。 MotionEvent#getSource() source运动事件的 指定收到的输入的类。 此方法的实现必须在处理事件之前检查源中的位。 下面的代码示例演示如何执行此操作。

具有源类 InputDevice#SOURCE_CLASS_POINTER 的泛型运动事件将传递到指针下的视图。 所有其他泛型运动事件将传送到焦点视图。

public boolean onGenericMotionEvent(MotionEvent event) {
                if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        // process the joystick movement...
                        return true;
                    }
                }
                if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_HOVER_MOVE:
                            // process the hover movement...
                            return true;
                        case MotionEvent.ACTION_SCROLL:
                            // process the scroll wheel movement...
                            return true;
                    }
                }
                return super.onGenericMotionEvent(event);
            }

android.view.View.onGenericMotionEvent(android.view.MotionEvent)Java 文档。

此页面的部分内容是基于 创建和共享的工作进行的修改,并根据 署名许可中所述的术语使用。

适用于