简体   繁体   English

如何在onDraw方法之外使用canvas?

[英]How can I use canvas outside the onDraw method?

I need to draw something on the same canvas that onDraw() get access to. 我需要在onDraw()访问的同一个画布上绘制一些东西。

This works fine as long as I am inside OnDraw(), but I don't know how to get that canvas when I'm outside. 只要我在OnDraw()内部,这样就可以正常工作,但是当我在外面时,我不知道如何获得该画布。

Thanks for any suggestions. 谢谢你的任何建议。

@Override
protected void onDraw(Canvas canvas) {
    canvas.doSomething  // works fine
}

//new method to draw omething on the same canvas
mydraw(how to get canvas in here?){}

onDraw由系统调用,你应该在那里调用你的绘图,你总是可以将Canvas作为参数传递给你的myDraw方法

You can try to send canvas to your own method: 您可以尝试将canvas发送到您自己的方法:

@Override
protected void onDraw(Canvas canvas) {
    yourMethod(canvas);
}

void yourMethod(Canvas canvas){
    //TODO
    //your code goes here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM