0
我正在爲android編寫一個應用程序,我有一個擴展視圖的類設置。在那個班裏面,我正在覆蓋onDraw。跨班分享畫布?
我有另一個類,我正在做很多處理。我想知道是否有一種方法可以在第二課中使用onDraw方法?第二堂課不擴展任何東西。
我正在爲android編寫一個應用程序,我有一個擴展視圖的類設置。在那個班裏面,我正在覆蓋onDraw。跨班分享畫布?
我有另一個類,我正在做很多處理。我想知道是否有一種方法可以在第二課中使用onDraw方法?第二堂課不擴展任何東西。
您可以從第一個實例化第二個類,然後將您接收的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
}
我試過了,我想我可以得到一個快速示例嗎? – Dave 2011-01-27 20:04:40