Java 单击按钮可使用鼠标滚动工作设置GenericMotionListener事件
先生, 我正在使用按钮键,它会显示一些值,例如:5,如果我将鼠标光标指向按钮,然后,在使用鼠标滚动的setOnGenericMotionListener事件上,Eg:5根据鼠标滚动的不同来增加和减少值,但现在我想移动鼠标光标点的任何位置,需要使用鼠标滚动事件设置setOnGenericMotionListener事件来处理特定按钮如何执行此事件 活动Java 单击按钮可使用鼠标滚动工作设置GenericMotionListener事件,java,android,mouseevent,motionevent,Java,Android,Mouseevent,Motionevent,先生, 我正在使用按钮键,它会显示一些值,例如:5,如果我将鼠标光标指向按钮,然后,在使用鼠标滚动的setOnGenericMotionListener事件上,Eg:5根据鼠标滚动的不同来增加和减少值,但现在我想移动鼠标光标点的任何位置,需要使用鼠标滚动事件设置setOnGenericMotionListener事件来处理特定按钮如何执行此事件 活动 您不应使用此方法检测触摸事件。 在View.onGenericmotionEvent描述中: /** * Implement t
您不应使用此方法检测触摸事件。 在View.onGenericmotionEvent描述中:
/**
* Implement this method to handle generic motion events.
* <p>
* Generic motion events describe joystick movements, mouse hovers, track pad
* touches, scroll wheel movements and other input events. The
* {@link MotionEvent#getSource() source} of the motion event specifies
* the class of input that was received. Implementations of this method
* must examine the bits in the source before processing the event.
* The following code example shows how this is done.
* </p><p>
* Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER}
* are delivered to the view under the pointer. All other generic motion events are
* delivered to the focused view.
* </p>
* <pre> 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 mouse hover movement...
* return true;
* case MotionEvent.ACTION_SCROLL:
* // process the scroll wheel movement...
* return true;
* }
* }
* return super.onGenericMotionEvent(event);
* }</pre>
*
* @param event The generic motion event being processed.
* @return True if the event was handled, false otherwise.
*/
public boolean onGenericMotionEvent(MotionEvent event) {
return false;
}
/**
*实现此方法以处理一般运动事件。
*
*通用运动事件描述操纵杆运动、鼠标悬停、轨迹板
*触摸、滚轮移动和其他输入事件。这个
*运动事件的{@link MotionEvent#getSource()source}指定
*接收到的输入的类别。此方法的实现
*必须在处理事件之前检查源中的位。
*下面的代码示例演示了如何实现这一点。
*
*源类为{@link InputDevice#源类为(指针)的通用运动事件
*被传递到指针下的视图。所有其他通用运动事件都是
*交付给焦点视图。
*
*公共布尔onGenericMotionEvent(运动事件){
*if(event.isFromSource(InputDevice.SOURCE\u CLASS\u操纵杆)){
*if(event.getAction()==MotionEvent.ACTION\u MOVE){
*//处理操纵杆移动。。。
*返回true;
* }
* }
*if(event.isFromSource(InputDevice.SOURCE\u CLASS\u指针)){
*开关(event.getAction()){
*case MotionEvent.ACTION\u HOVER\u MOVE:
*//处理鼠标悬停移动。。。
*返回true;
*case MotionEvent.ACTION\u滚动:
*//处理滚轮移动。。。
*返回true;
* }
* }
*返回super.onGenericMotionEvent(事件);
* }
*
*@param event正在处理的通用运动事件。
*@如果事件已处理,则返回True,否则返回false。
*/
公共布尔onGenericMotionEvent(运动事件){
返回false;
}
您可以找到此方法的一些使用案例
顺便说一句,你应该使用手势检测器来处理你的手势
/**
* Implement this method to handle generic motion events.
* <p>
* Generic motion events describe joystick movements, mouse hovers, track pad
* touches, scroll wheel movements and other input events. The
* {@link MotionEvent#getSource() source} of the motion event specifies
* the class of input that was received. Implementations of this method
* must examine the bits in the source before processing the event.
* The following code example shows how this is done.
* </p><p>
* Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER}
* are delivered to the view under the pointer. All other generic motion events are
* delivered to the focused view.
* </p>
* <pre> 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 mouse hover movement...
* return true;
* case MotionEvent.ACTION_SCROLL:
* // process the scroll wheel movement...
* return true;
* }
* }
* return super.onGenericMotionEvent(event);
* }</pre>
*
* @param event The generic motion event being processed.
* @return True if the event was handled, false otherwise.
*/
public boolean onGenericMotionEvent(MotionEvent event) {
return false;
}