Runnable
I将
MyRender
定义为Runnable
,请要求重新绘制,我将其发布到主循环中:
Looper.getMainLooper().post(MyRender);
然后,渲染逻辑在
run()
中执行:MyRender.run() {
PaintTheSurface();
}
eption2:使用
Choreographer.FrameCallback
,我将
MyRender
定义为Choreographer.FrameCallback
,并要求使用以下方式进行重新修复:
Choreographer.getInstance().postFrameCallback(MyRender);
然后在
doFrame()
中执行渲染逻辑::
MyRender.doFrame(frameTimeNanos: Long) {
PaintTheSurface();
}
我的观察结果我尝试了这两种方法,但是从视觉上看,我没有注意到任何区别。我不确定选择哪种方法以及每种方法的优势和缺点是什么。
在我的应用程序中,需要重新绘制的动画已经使用
Choreographer
同步。但是,据我所知,其他可能触发重新绘制的事件(例如触摸或鼠标移动事件)不是由Choreographer
.
使用
Runnable
vs.
Choreographer.FrameCallback
请求重新绘制的利弊是什么?
如果我使用Choreographer
,它如何处理触摸或鼠标移动事件,这些事件可能不会与编舞者的框架计时同步?
使用
Looper.getMainLooper().post(runnable)
重新征用redraw 有一个严重的缺点:
编排者及其
postFrameCallback()