我的项目是基于surfaceView的,到目前为止,我已经在onDraw中完成了所有的渲染,这是我要重写的。一切似乎都好起来了。
但是,我刚刚更新了我的SDK,现在它给了我一个错误,告诉我:
可疑方法调用;应该调用“绘图”而不是"onDraw“
谁能解释一下这两者的区别吗?
我在网上读过一些类似的问题,但我没有找到我能理解的解释。
谢谢
发布于 2013-02-14 00:14:56
SurfaceView.draw()基本上是调用View.draw();,如果您想要实现您的绘图,您应该在View.onDraw()中这样做,这是您要实现的,甚至在源代码注释中也是这样做的。
ViewGroup.drawChild()调用此方法使每个子视图自己绘制。此not ()方法是一个实现细节,不打算被重写或从ViewGroup.drawChild()以外的任何其他地方调用。
至于它们之间的区别:
抽签():
13416 /*
13417 * Draw traversal performs several drawing steps which must be executed
13418 * in the appropriate order:
13419 *
13420 * 1. Draw the background
13421 * 2. If necessary, save the canvas' layers to prepare for fading
13422 * 3. Draw view's content
13423 * 4. Draw children
13424 * 5. If necessary, draw the fading edges and restore layers
13425 * 6. Draw decorations (scrollbars for instance)
13426 */onDraw()为空。该由你来实施了。
发布于 2013-05-28 08:10:28
我试着清理我的项目,它确实解决了问题。试试看。
发布于 2013-09-05 08:53:59
从那以后我就有问题了。
我是这样处理的:
1)声明如下方法。
@SuppressLint("WrongCall")
public void drawTheView() {
theCanvas = null;
try{
theCanvas = getHolder().lockCanvas();
if(theCanvas != null) {
onDraw(theCanvas);
}
} finally {
getHolder().unlockCanvasAndPost(theCanvas);
}
}2)现在可以修改onDraw()方法:
@Override
public void onDraw(Canvas canvas) {
//Do some drawing
}您可以从任何地方调用drawTheView()方法,并以这种方式调用onDraw()方法,而不会出现错误.
我认为这是一种实用的方法。
https://stackoverflow.com/questions/14865434
复制相似问题