我想通過使用for循環繪製多個餅圖,並將數據存儲在數組中(data[][][]
)。當每個圖表繪製完成後,我將頂部和底部加上450(top+=450; bottom+=450;
)以避免圖表重疊。但結果是餅圖不斷地向下移動。我嘗試在行尾添加invalidate()
,但它不起作用。Android:爲什麼無盡循環在onDraw()?
private String data[][][]=... //store some data
private float left=50,top=100,right=450, bottom=500;
public void onDraw(Canvas c) {
super.onDraw(c);
Paint paint = new Paint();
RectF rec;
for(int j=0;j<data.length;j++){
rec=new RectF(left,top,right,bottom);
//draw a pie chart
for (int i = 0; i < data[j].length; i++) {
float drawDegree = (float)Integer.parseInt(data[j][i][1])/100* 360f;
c.drawArc(rec, -90, drawDegree, true, paint);
}
top+=450;
bottom+=450;
}
}
是你的循環? – kabuto178