2015-04-08 106 views
2

如何在圓弧的邊緣添加小圓。
它也應該沿着時鐘方向隨弧邊移動。
現在我成功地使用改變掃掠角度來動畫弧線。
剩餘黑點。在arc android的邊緣添加一個圓形?

enter image description here

下面

是getView的代碼和動畫類

--- init method and implement constructor ---- 

mRectF = new RectF(mWidth/2 - 360, mHeight/2 - 360, mWidth/2 + 360, mHeight/2 + 360); 

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    //draw circle background 
    mPaint.setColor(getResources().getColor(R.color.timer_background_color)); 
    canvas.drawCircle(mWidth/2, mHeight/2, 360, mPaint); 

    mPaint.setColor(getResources().getColor(R.color.actionbar_back_color)); 
    canvas.drawArc(mRectF, mStartAnagle, mSweepAngle, false, mPaint); 
} 

public class TimerAnimation extends Animation{ 

    public TimerAnimation (float startAngle, float sweepAngle, long duration) { 
     mStartAnagle = startAngle; 
     mSweepAngle = sweepAngle; 
     setDuration(duration); 
     setRepeatCount(Animation.INFINITE); 
     setInterpolator(new LinearInterpolator()); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     if (!isComplete) { 
      mSweepAngle = mSweepAngle + 6; 
      if (mSweepAngle >= 360) { 
       isComplete = true; 
       mSweepAngle = 360; 
      } 
     } else { 
      mStartAnagle = mStartAnagle + 6; 
      mSweepAngle = mSweepAngle - 6; 
      if (mStartAnagle >= 360) 
       mStartAnagle = 0; 
      if (mStartAnagle == 270 || mSweepAngle <= 0) { 
       isComplete = false; 
       mSweepAngle = 0; 
      } 
     } 
     invalidate(); 
    } 
} 

回答

2

也許你應該使用Path

Path path = new Path(); 
// Set the starting position of the path to (0,0). 
path.moveTo(0, 0); 
path.arcTo(...); //draw your arc here 
path.circleTo(); //draw a small circle here at the end of arc 

而且也許你應該calc the arc's end position並以此爲中心使用爲小圓圈。

+0

謝謝。讓我先檢查一下。 – Moinkhan

+0

感謝您的鏈接@Stan – Moinkhan

1

步驟1:計算黑點的

推薦的中心位置爲(的centerX,centerY)的位置,黑點的位置爲(X,Y),然後,

x = radius * cos(mStartAnagle+mSweepAngle) + centerX; 
y = radius * sin(mStartAnagle+mSweepAngle) + centerY; 

步驟2:繪製黑點

推薦點圖像是R.drawable.dot

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.dot) 
          .copy(Bitmap.Config.ARGB_8888, true); 
canvas.drawBitmap(bitmap, x, y, null);