更新时间:2023-02-05 18:03:26
我认为您已经回答了自己的问题.为什么不呢?
I think you answered your question yourself. Why not:
public class DrawListenerView extends View{
private Callback callback;
public DrawListenerView(Callback callback){
this.callback = callback;
}
@Override
protected void onDraw (Canvas canvas){
super.onDraw(canvas);
//add your method here you want to call
//Or use a Callback-pattern
callback.finish();
}
}
public interface Callback(){
public void finish();
}
如果您查看来源:
使整个视图无效.如果该视图可见,则将来会在某个时候调用onDraw(android.graphics.Canvas).必须从UI线程调用此方法.要从非UI线程进行调用,请调用postInvalidate().
Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will >be called at some point in the future. This must be called from a UI thread. To call from >a non-UI thread, call postInvalidate().
尝试一下:)
可能您想使用回调来处理此问题.
probably you want to use a Callback to handle this.