2012-01-05 194 views
2

有沒有辦法在繪製之前在畫布上安排可繪製的繪圖?我的意思是設置哪個drawable將會繪製在前面,哪個drawable會繪製在後面。安排畫布上繪製的繪圖

回答

3

它們按您繪製的順序繪製。試試先畫一張,最後一張。

+1

我知道,我需要更好的方法 – Liukas 2012-01-05 11:37:41

+0

那麼......然後你正在尋找類似z-index的東西,對吧?至於據我所知沒有這樣的事情。但是如果你知道你的drawable應該有哪個z-index,只需要命令它們並以這種方式繪製它們即可。它沒有什麼區別。或者給自己寫一個類,讓你給所有的drawable和z-index,並按照正確的順序繪製它們。問題究竟在哪裏? – mseo 2012-01-05 22:23:44

+0

嗯,你看,我想要一個drawable在另一個drawable中繪製在for循環中。但我不希望它在循環中繪製的所有drawable的後面,所以把代碼放在第一位並不會幫助我:/ – Liukas 2012-01-05 23:24:53

0

稍後您可以繪製到臨時畫布以繪製到主畫布。

Picture iconFrame = new Picture(); 
Canvas tempCanvas = iconFrame.beginRecording(width, height); 
// width and height refer to the intended destination canvas size 

... 
// Any configuration before performing the draw should be done here 

tempCanvas.drawPath(...); 
tempCanvas.drawBitmap(...); 
// Any required draw commands for this image should be done to tempCanvas 

iconFrame.endRecording(); 

... 
// Any other configuration or draw commands can be done here 

iconFrame.draw(canvas); 
// Assigns the content of tempCanvas to the top of the main Canvas 

在我的情況下,自定義路徑中我的形象的PorterDuff操作如果因爲後來抽獎損壞它,它是第一隻進行工作。

0

一個辦法做到這一點是有你畫定義的z-index變量的一切,並收集你在一個點繪製的一切,並把它們在列表中,你再畫它爲了用的z-index之前。

例如:

Interface IDrawable{ 
    int getZ(); 
    void draw(); 
} 

class drawMe implements IDrawable{ 
    @overrider 
    draw(){ 
    /// do my drawing 
    } 

    @override 
    int getZ() {return z; } 
} 

繪圖或主類

List<IDrawable> myList= new ArrayList(); 
myList.Add(new DrawMe()); 

,並在您的抽獎方法

for(IDrawable draw : myList.OrderBy(z){ 
    draw.draw(); 
} 

這就是概念反正