【问题标题】:How to spin bitmap along with Circle ProgressBar?如何将位图与 Circle ProgressBar 一起旋转?
【发布时间】:2016-10-19 09:23:02
【问题描述】:

我正在尝试修改这个库:https://github.com/Shinelw/ColorArcProgressBar

这就是我到目前为止所做的,没有紫色圆圈指示器arc progress bar

我的问题是:如何使紫色圆圈与进度一起制作动画(如图所示)?

在扩展 View 的 ColorArcProgressBar 类中,在 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);

现在,我怎样才能像进度一样沿着弧线制作动画?

【问题讨论】:

    标签: android android-animation android-custom-view android-bitmap ondraw


    【解决方案1】:

    这个没试过,如果不正确就关闭了……

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

    这有助于您的位图是圆形的,因此我们不必旋转它...

    【讨论】:

    • 我尝试了一些东西,但现在我发现我忘记了我们需要处理 cos 和 sin,我的 x 和 y 是一样的,但没有 cos 和 sin。
    猜你喜欢
    • 1970-01-01
    • 2023-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多