0

Je suis en train de modifier un peu cette bibliothèque: https://github.com/Shinelw/ColorArcProgressBarComment faire pour filer bitmap avec Circle ProgressBar?

Et ce que je l'ai fait jusqu'à présent, sans l'indicateur de cercle violet: arc progress bar

Ma question est: comment puis-je animer le cercle violet avec la progression (comme indiqué dans l'image)?

classe à l'intérieur ColorArcProgressBar qui se prolonge View, méthode onDraw, voici comment les progrès sont dessiner: canvas.drawArc(bgRect, startAngle, currentAngle, false, progressPaint);

et l'animation est

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(); 

} 

J'ai réussi à positionner le bitmat violet au début de le progrès comme ceci:

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

Maintenant, comment puis-je l'animer le long de l'arc comme la progression?

Répondre

0

N'a pas essayer cela, si ce qui ne va pas, il est proche ...

// 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); 

Il a aidé que votre bitmap est circulaire, donc nous ne pas faire tourner que ...

+0

Cela fonctionne parfaitement! Merci beaucoup! – JuLes

+0

J'ai essayé certaines choses, mais maintenant je vois que j'ai oublié que nous devons travailler avec vith cos et le péché, mon x et y était le même mais sans cos et péché. – JuLes