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);
    }
相关推荐
BeiGuTing_code11 小时前
Java泛型与Object
java·开发语言
惊讶的猫11 小时前
Tika文档解析
java
HEJOO912 小时前
Java 类加载过程详解:从加载到初始化的完整链路
java·开发语言·firefox
科学熊12 小时前
Java 分布式理论与高并发编程
java·开发语言·分布式
砚底藏山河12 小时前
python量化实操:回测数据缓存与重放
java·python·金融·1024程序员节
学长毕设12 小时前
基于springboot的农资管理系统-附源码
java·spring boot·后端
晒太羊的猫12 小时前
hot100子串
java·算法·leetcode
开开心心就好13 小时前
本地文件搜索工具,双击Ctrl就能呼出搜索
java·服务器·前端·支持向量机·ffmpeg·音视频·模拟退火算法
独隅13 小时前
Claude 高效使用指南深度评测
java·开发语言·claude·claude code