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);
    }
相关推荐
小强库计算机毕业设计13 小时前
SpringBoot+Vue3 学生宿舍管理系统实战
java·spring boot·后端·vue·学生宿舍管理系统
李冰然13 小时前
深入Java集合框架:HashMap源码解析(JDK 8)
java
安卓与AI研习社13 小时前
Android ANR 到底怎么定位?从触发原理到日志判断的完整方法
android
人道领域14 小时前
【0-1的agent进阶篇】RAG:从Embedding到检索增强生成的底层逻辑
java·embedding·agent·rag
桦说编程14 小时前
盘点并发集合里那些容易误判的行为
java·后端·性能优化
阿pin15 小时前
Android随笔-MVI
android·mvi
leobertlan15 小时前
【好玩系列】训练一个神经网络指导小孩玩游戏
android·机器学习·程序员
IT爱学堂15 小时前
java版数据结构和算法+AI算法和技能学习指南
java·开发语言
Android-Flutter16 小时前
android LeakCanary 工作原理 详解
android·kotlin
evans在进步16 小时前
LeetCode 394:字符串解码——Java 单栈模拟与嵌套解析详解
java·python·leetcode