CircleProgress icon indicating copy to clipboard operation
CircleProgress copied to clipboard

问个小问题~

Open junchenChow opened this issue 8 years ago • 3 comments

请教一下 进度的最前方加一个小圆点该怎么实现 default 像这样~

junchenChow avatar Feb 14 '17 04:02 junchenChow

可以通过这个函数,传入大圆的圆心坐标、半径和斜率,计算出小圆点的圆心坐标 。

public class GeometryUtil {
     /**
      * Get the point of intersection between circle and line.
      * 获取 通过指定圆心,斜率为lineK的直线与圆的交点。
      * 
      * @param pMiddle The circle center point.
      * @param radius The circle radius.
      * @param lineK The slope of line which cross the pMiddle.
      * @return
      */
    public static PointF[] getIntersectionPoints(PointF pMiddle, float radius, Double lineK) {
        PointF[] points = new PointF[2];

        float radian, xOffset = 0, yOffset = 0;
        if (lineK != null) {
            radian = (float) Math.atan(lineK);
            xOffset = (float) (Math.sin(radian) * radius);
            yOffset = (float) (Math.cos(radian) * radius);
        } else {
            xOffset = radius;
            yOffset = 0;
        }
        points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y - yOffset);
        points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y + yOffset);

        return points;
    }
}

EthanCo avatar Feb 14 '17 13:02 EthanCo

@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.rotate(progressInitialPosition, mCenter.x, mCenter.y); canvas.drawArc(mPaintRectF, 0, maxProgress, isSolid, bgPaint); canvas.drawArc(mPaintRectF, 0, -currProgress, isSolid, forePaint); PointF[] points = getIntersectionPoints(mCenter, mWidth / 2 - mStrokeWidth, Math.toRadians(-currProgress)); canvas.drawCircle(points[0].x, points[1].y, 20, smallCirclePointPaint); } 计算这一方面真是硬伤。。。

junchenChow avatar Feb 15 '17 02:02 junchenChow

你的canvas.drawCircle写错了,getIntersectionPoints获取的交点有两个,points[0]是一个交点,points[1]是另一个交点

EthanCo avatar Feb 15 '17 06:02 EthanCo