Android onTouchEvent工作 [英] android onTouchEvent work

查看:102
本文介绍了Android onTouchEvent工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过扩展"SurfaceView"创建了自己的自定义视图类.然后,我重写onTouchEvent方法.两个问题.

I have created my own custom view class by extending "SurfaceView." I then override the onTouchEvent method. Two questions.

(1)即使我处理了我所需要的一切(我认为),我是否应该都同时调用super.onTouchEvent? (2)是否应该在新线程中完成工作?我收到许多 跳过了32帧!该应用程序可能在其主线程上做过多的工作 ?是从UI线程调用了onTouchEvent吗?

(1) Should I even both calling the super.onTouchEvent even though I handle everything (I think) I need? (2) Should have the work done in a new thread? I am receiving many Skipped 32 frames! The application may be doing too much work on its main thread Is the onTouchEvent called from the UI thread?

我的观点不过是操纵杆,在触摸事件上,我只需用3或4行代码移动对象的坐标即可.

My view is nothing more than a joy stick and on the on touch event I simply move the coordinates of an object with 3 or 4 lines of code.

推荐答案

  1. 在这里不必调用superOnTouchEvnet.但是请记住,如果返回false,它将无法工作.因此,如果要处理事件,最好在完成任务后返回super.OnTouchEvent.如果对于某些情况或某些输入,您不想处理touch事件,则无需使用super方法,只需返回false.

  1. Here it is not necessarey to call superOnTouchEvnet.But remember that if you return false it wont work. so it is better to return super.OnTouchEvent after finishing task if you want to handle the event. If for some casees or for some input you dont want to handle the touch event then without using the super method just return false.

是.此方法由主UI线程处理.因此对于长任务,请使用任何安全的方法,例如使用不同的线程,asynctask或handler.post.

yes. this method is handled by main UI thread. so for long tasks use any safe methods like using different threads, asynctask or handler.post.

这篇关于Android onTouchEvent工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆