在看RecyclerView源码的时候发现有一个方法实现,叫onGenericMotionEvent(MotionEvent event),从方法注释看是专门响应一些外接设备的操作的,比如游戏手柄,鼠标,滚轮,触控板等。从RecyclerView的onGenericMotionEvent实现来看,确实也是如此。
代码如下:

public boolean onGenericMotionEvent(MotionEvent event) {if (mLayout == null) {return false;}if (mLayoutFrozen) {return false;}if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {final float vScroll, hScroll;if ((event.getSource() & InputDeviceCompat.SOURCE_CLASS_POINTER) != 0) {if (mLayout.canScrollVertically()) {// Inverse the sign of the vertical scroll to align the scroll orientation// with AbsListView.vScroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);} else {vScroll = 0f;}if (mLayout.canScrollHorizontally()) {hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);} else {hScroll = 0f;}} else if ((event.getSource() & InputDeviceCompat.SOURCE_ROTARY_ENCODER) != 0) {final float axisScroll = event.getAxisValue(MotionEventCompat.AXIS_SCROLL);if (mLayout.canScrollVertically()) {// Invert the sign of the vertical scroll to align the scroll orientation// with AbsListView.vScroll = -axisScroll;hScroll = 0f;} else if (mLayout.canScrollHorizontally()) {vScroll = 0f;hScroll = axisScroll;} else {vScroll = 0f;hScroll = 0f;}} else {vScroll = 0f;hScroll = 0f;}if (vScroll != 0 || hScroll != 0) {scrollByInternal((int) (hScroll * mScaledHorizontalScrollFactor),(int) (vScroll * mScaledVerticalScrollFactor), event);}}return false;}

RecyclerView只正对滚动事件做了处理,然后我们可以通过event.getSource()方法获取到是哪个外接设备触发的事件,有兴趣的同学可以看一下。

android onGenericMotionEvent(MotionEvent event)相关推荐

  1. Android的MotionEvent和事件处理

    之前几篇文章我们讲解了自定义View和ViewGroup, 今天我们来看下View和ViewGroup常见的触摸事件和按键事件. MotionEvent MotionEvent对象是与用户触摸相关的时 ...

  2. Android中MotionEvent的来源和ViewRootImpl

    前言 很久没有发表文章了,今天来一篇,大家撒花--- 本文打算分析下Android中点击事件的来源,顺便提及下ViewRootImpl. Android中点击事件的来源 这个问题,也许你会说" ...

  3. Android 中input event的分析

    2019独角兽企业重金招聘Python工程师标准>>> 文章将分析Android 的Input Event 子系统的来龙去脉. Android 系统里面有很多小工具,运行这些工具,我 ...

  4. Android通过MotionEvent仿真手指在屏幕单次点击事件

    Android通过MotionEvent仿真手指在屏幕单次点击事件 Android的View有一个方法performClick(),可人工模拟用户在手机屏幕上的点击事件,这次换一种方法,通过代码制造M ...

  5. android input设备event处理以及hotplug检测

    android平台2.3.4,发现插上usb鼠标和键盘开机,那么都能正常使用,一旦拔出以后再插回去,就不能使用了. 首先检测/dev/input下的设备节点是否正常,发现拔出和插入设备,节点文件都能正 ...

  6. 【Android应用开发】RecycleView API 翻译 (文档翻译)

    . RecyclerView extends ViewGroup implements ScrollingView NestedScrollingChild java.lang.Object    ↳ ...

  7. android鼠标滚轮事件坐标,android 处理鼠标滚轮事件 【转】

    android处理鼠标滚轮事件,并不是如下函数: 1)  public boolean onKeyDown(int keyCode, KeyEvent event) 2)     public boo ...

  8. Unity3D研究院之Android同步方法读取streamingAssets

    版本Unity5.3.3 Android 小米pad1 首先非常感谢 @守着阳光 同学在下面的留言.让我解决了一个大的谜团.. 开始我知道 StreamingAssets 路径是这个 path = & ...

  9. android 处理鼠标滚轮事件 【转】

    android处理鼠标滚轮事件,并不是如下函数: 1)  public boolean onKeyDown(int keyCode, KeyEvent event) 2)     public boo ...

最新文章

  1. 一秒刹停!让特斯拉都「拜服」的无人车,竟送起了外卖!
  2. Science:纽约西奈山医学院房刚组定量分析真核生物DNA 6mA解析细菌污染的影响...
  3. 数据库常用sql语句
  4. 国赛无望,兄弟尽力了
  5. Python + logging 输出到屏幕,将log日志写入文件(亲测)
  6. Spring注解方式实现定时器
  7. 【LeetCode 986】 区间列表的交集(区间交集)
  8. 那天,他无意间瞟了眼程序员的桌面……
  9. mysql查询有数据但返回null_Mybatis查不到数据查询返回Null问题
  10. 在此iphone上尚未受信任_通知:这5款iPhone过保依然可以免费维修
  11. matlab 程序运行报错 调试 不退出函数
  12. 写给新入职的毕业生们
  13. libgdx游戏引擎开发笔记(八)SuperJumper游戏例子的讲解(篇二)---- 游戏界面跳转...
  14. CCNA学习要点,希望能对初学者有帮助
  15. 微信公众号点击图片跳转关注
  16. GameFi市值飙升,详解N.Fans目前的发展现状以及未来前景
  17. hitb2018_gundam —— tcache double free
  18. hover出不来是什么原因css,关于css的:hover失效问题
  19. 网站留言板防重复留言_公众号留言板怎么弄
  20. 我的Bug日常:spark基于yarn运行时抛错,内存不足Required executor memory (1024 MB), offHeap memory (0) MB。问题已解决,亲测有用~~~

热门文章

  1. [附源码]Python计算机毕业设计大学生社团管理系统
  2. java xsl转换pdf_Java 生成PDF文档-阿里云开发者社区
  3. Python爬虫:ZzzFun动漫视频网
  4. python函数实验总结_Python程序设计实验报告:实验六 函数
  5. 通用表表达式实现 UPDATE/DELETE LIMIT
  6. 随机变量序列的两种收敛性
  7. word中每页后面的空白怎么删掉
  8. 解决Ubuntu Linux终端输入命令没有颜色提示的设置方法
  9. 什么是虚拟机?Mac电脑怎么使用虚拟机安装双系统?
  10. 小波变换(DWT),短时傅里叶分析(STFT),与快速傅里叶(FFT)之间的关系