私は Android 用のアプリを作成しており、View を拡張するクラスをセットアップしています。そのクラス内で onDraw を上書きしています。
私は多くの処理を行っている別のクラスを持っています。2番目のクラス内でもonDrawメソッドを使用できる方法があるかどうか疑問に思っていましたか? 2 番目のクラスは何も拡張していません。
最初のクラスから 2 番目のクラスをインスタンス化してから、パラメーターとして受け取った Canvas を必要な 2 番目のウィッチのメソッドに渡すことができます。
何かのようなもの。
public void onDraw(Canvas canvas){
super.onDraw(canvas);
MyDrawer drawer = new MyDrawer(); //The 2nd class
canvas.store(); //Use it to store the actual matrix and any further change you can do in the paint method will not take effect over the original matrix
drawer.drawOn(canvas);
canvas.restore();//Return the original matrix, any new paint will use the original matrix
}