2013-01-10 50 views
1

我必須在畫布上繪製圓形,其形狀隨着直徑長度的改變而不斷變化。 (請注意,Diameter長度根據意圖數據修改)。我們可以證明就像從大尺寸到小尺寸)如何在android中動態/動態調整圓形的形狀?

我當前的圈子代碼看起來像下面,(這裏面的onCreate)

bitmap = Bitmap.createBitmap((int) getWindowManager() 
      .getDefaultDisplay().getWidth(), (int) getWindowManager() 
      .getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888); 
     canvas = new Canvas(bitmap); 
     paint = new Paint(); 
     paint.setColor(Color.BLACK); 
     paint.setStyle(Paint.Style.STROKE); 

     drawingImageView.setImageBitmap(bitmap); 
    // Draw Circle 
     canvas.drawCircle(50, 50, 20, paint); // circle example 

我使用的ImageView相同形狀的平穩過渡。我怎樣才能動態改變同一個圓的大小。有像下面的接收器

registerReceiver() 
    onReceive(Context c,Intent i){ 
// Based on data , modify the drawn Circle 
} 

OnReceive將收到意圖和基於數據,我們需要保持圓形狀的變化。當我將drawCircle代碼放在onReceive中時,它不會渲染圓。

在此先感謝。

回答

1

我寧願使用SurfaceView而不是ImageView +位圖。一個可能的解決辦法是這樣的:

SurfaceHolder mHolder = mSurfaceView.getHolder(); 

Canvas canvas = mHolder.lockCanvas(); 
yourDrawCircleMethod(canvas); 
canvas.unlockCanvasAndPost(); 

請注意,您還應該實現一個SurfaceHolder.Callback得到通知有關SurfaceViews狀態。