如何将位图与 Circle ProgressBar 一起旋转?
How to spin bitmap along with Circle ProgressBar?
我正在尝试稍微修改一下这个库:https://github.com/Shinelw/ColorArcProgressBar
这就是我到目前为止所做的,没有紫色圆圈指示器:
arc progress bar
我的问题是:我怎样才能使紫色圆圈随着进度动画化(如图所示)?
在扩展视图的 ColorArcProgressBar class 中,在 onDraw 方法中,进度是这样绘制的: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();
}
我设法像这样在进度开始时定位紫色位垫:
canvas.drawBitmap(mIcon,bgRect.left+mIcon.getWidth()/2 +30, bgRect.bottom - 40 +mIcon.getHeight()/2 , null);
现在,我怎样才能像进度一样沿着弧线制作动画呢?
没试过这个,如果不对就接近...
// 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);
这有助于您的位图是圆形的,因此我们不必旋转它...
我正在尝试稍微修改一下这个库:https://github.com/Shinelw/ColorArcProgressBar
这就是我到目前为止所做的,没有紫色圆圈指示器: arc progress bar
我的问题是:我怎样才能使紫色圆圈随着进度动画化(如图所示)?
在扩展视图的 ColorArcProgressBar class 中,在 onDraw 方法中,进度是这样绘制的: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();
}
我设法像这样在进度开始时定位紫色位垫:
canvas.drawBitmap(mIcon,bgRect.left+mIcon.getWidth()/2 +30, bgRect.bottom - 40 +mIcon.getHeight()/2 , null);
现在,我怎样才能像进度一样沿着弧线制作动画呢?
没试过这个,如果不对就接近...
// 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);
这有助于您的位图是圆形的,因此我们不必旋转它...