0

我想修改一點點這個庫:https://github.com/Shinelw/ColorArcProgressBar如何將位圖與Circle ProgressBar一起旋轉?

而且這是我到目前爲止已經完成,沒有紫色圓形指示燈arc progress bar

我的問題是:我怎麼能動畫紫色圓圈和進度(如圖所示)?

擴展視圖,在的onDraw方法

裏面ColorArcProgressBar類,這是進步的是如何得出:canvas.drawArc(bgRect, startAngle, currentAngle, false, progressPaint);

和動畫

private void setAnimation(float last, float current, int length) { 
    progressAnimator = ValueAnimator.ofFloat(last, current); 
    progressAnimator.setDuration(length); 
    progressAnimator.setTarget(currentAngle); 
    progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

     @Override 
     public void onAnimationUpdate(ValueAnimator animation) { 
      currentAngle = (float) animation.getAnimatedValue(); 
      curValues = currentAngle/k; 
     } 
    }); 
    progressAnimator.start(); 

} 

我設法紫色bitmat在起始位置這樣的進展:

canvas.drawBitmap(mIcon,bgRect.left+mIcon.getWidth()/2 +30, bgRect.bottom - 40 +mIcon.getHeight()/2 , null); 

現在,我怎樣才能像沿着圓弧進行動畫?

回答

0

沒有嘗試了這一點,如果這是不對的已經很接近了......

// since currentAngle is a "sweep" angle, the 
    // final angle should be current + start 
    float thetaD = startAngle + currentAngle; 
    if (thetaD > 360F) { 
     thetaD -= 360F; 
    } 

    // convert degrees to radians 
    float theta = (float) Math.toRadians(thetaD); 

    // polar to Cartesian coordinates 
    float x = (float) (Math.cos(theta) * bgRect.width()/2) + bgRect.centerX(); 
    float y = (float) (Math.sin(theta) * bgRect.height()/2) + bgRect.centerY(); 

    canvas.drawBitmap(mIcon, x - mIcon.getWidth()/2, y - mIcon.getHeight()/2 , null); 

它幫助您的位圖是圓形的,所以我們沒有旋轉那......

+0

它完美的工作!非常感謝! – JuLes

+0

我嘗試了一些東西,但現在我發現我忘了我們需要工作與罪惡和罪惡,我的X和Y是一樣的,但沒有COS和罪惡。 – JuLes