android鼠标滚轮事件监听方法

复制代码
@Override
    public boolean onGenericMotionEvent(MotionEvent event) {
//The input source is a pointing device associated with a display.
//输入源为可显示的指针设备,如:mouse pointing device(鼠标指针),stylus pointing device(尖笔设备)
        if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
            switch (event.getAction()) {
                // process the scroll wheel movement...处理滚轮事件
                case MotionEvent.ACTION_SCROLL:
                    //获得垂直坐标上的滚动方向,也就是滚轮向下滚
                    if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f) {
                        LogUtils.d("fortest::onGenericMotionEvent down");
                       
                    }
                    //获得垂直坐标上的滚动方向,也就是滚轮向上滚
                    else {
                        LogUtils.i("fortest::onGenericMotionEvent up");
                        
                    }
                    
                    return true;
            }
        }
        return super.onGenericMotionEvent(event);
    }
相关推荐
studyForMokey6 小时前
【Android 面试】Paging3
android·面试·职场和发展
企业数字化笔记6 小时前
租户停用后数据和任务怎么处理?冻结、恢复与保留策略的实现
android·java·spring boot
CarIise6 小时前
Spring MVC 请求参数绑定与常用注解
java·spring·mvc
一条泥憨鱼7 小时前
AI Agent 安全实践:从 MCP 工具调用到 Java 权限校验
java·人工智能·安全
Nebula_g7 小时前
云禾外卖补充—项目整体后端运行逻辑-对流程的更深层次理解
java·开发语言·网络·数据库·状态模式·javase
萧瑟余晖7 小时前
Spring Security 6.x新特性与架构演进详解
java·spring·架构
\光辉岁月/7 小时前
1.Object类
java·面向对象·object类
鸽鸽程序猿7 小时前
【项目】【在线判题系统】公共功能
java·spring boot·maven
一只笨菜鸟7 小时前
IDEA如何让多个项目同时显示
java·ide·intellij-idea
G018_star sky♬7 小时前
java中的字符串常见方法
java·开发语言