0

我正在为 android 编写一个应用程序,并且我有一个扩展 View 的类设置。在那个类里面我覆盖了onDraw。

我有另一堂课,我正在做很多处理。我想知道是否有一种方法可以在第二类中使用 onDraw 方法?第二类没有扩展任何东西。

4

1 回答 1

0

您可以从第一个类实例化第二个类,然后将您收到的 Canvas 作为参数传递给需要它的第二个女巫的方法。

就像是。

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
  }
于 2011-01-27T19:44:03.197 回答