Android MotionEvent ACTION_MOVE efficiency. How to improve performance?

佐手、 提交于 2019-12-04 07:25:17

The bottleneck is the drawing method, obviously.

If you are working on android 3.0+, draw all those crazy things on the GPU. Add the attribute

android:hardwareAccelerated="true"

to the <application> tag in your manifest. This will unbelievably increase drawing time.

Additionally, try to not redraw the whole thing if only a little needs to be updated. Invoke invalidate(Rect dirty) instead of invalidate().

You should also get more points by utilizing event.getHistoricalX/Y() functions

Put a small thread sleep in the motion event; that helped me solve the problem when a ton of movement events were jamming the listener.

Thread.sleep(100);

invalidate(); is harmful for performance. Try to calculate bounds rect and call invalidate(bounds)

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