android onTouchEvent work

試著忘記壹切 提交于 2019-12-13 04:48:08

问题


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

(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?

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:


  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.

  2. 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.



来源:https://stackoverflow.com/questions/13465911/android-ontouchevent-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!