What actually happens if I return false in a OnTouchListener?(如果我在 OnTouchListener 中返回 false,实际会发生什么?)
问题描述
我正在创建一个需要 SurfaceView 来实现 OnTouchListener 的游戏.在游戏过程中,我想暂停监听器一段时间.我尝试从 onTouch() 方法返回 false,但该方法仍然继续执行.有没有其他方法可以让监听器暂停有时?任何人请解释从 onTouch() 返回 false 的实际含义?
I am creating a game that requires a SurfaceView to implement OnTouchListener. During the game I want to pause the Listener for some specific time.I tried returning false from the onTouch() method , but still the method keeps executing.Is there any other way to have the listener paused for sometime? And anyone please explain what returning false from onTouch() actually mean?
推荐答案
从查看文档:
Returns
True if the listener has consumed the event, false otherwise.
如果你返回 true,你告诉 android 新闻已经处理好了.忘了它.
If you return true you tell android that the press is taken care of. Forget it.
如果您返回 false,您基本上是在说不是我的问题,其他人将不得不处理此点击".然后 android 会将事件传递给其他视图,这些视图可能在您的视图之下.
If you return false you basically say "Not my problem, Someone else will have to take care of this click". Then android will pass the event down to other views, which could be under your view.
这篇关于如果我在 OnTouchListener 中返回 false,实际会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果我在 OnTouchListener 中返回 false,实际会发生什么?
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
