Android - How to overlay one path on top of another

I currently have the following code:

private void drawGreen(Canvas canvas) {


    greenPaint.setColor(0xFF00AA00);

    if (start) {
        greenPath = new Path();
        greenPath.reset();
        greenPath.moveTo(pathArrayX.get(0), pathArrayY.get(0));
        start = false;
    }

    if (isInsideCircle(pathArrayX.get(pathIndex), pathArrayY.get(pathIndex), curX, curY, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, getResources().getDisplayMetrics()))) {
        greenPath.lineTo(pathArrayX.get(pathIndex), pathArrayY.get(pathIndex));
        canvas.drawPath(greenPath, greenPaint);
        pathIndex++;

    }


}

private boolean isInsideCircle(float x, float y, float centerX, float centerY, float radius) {
    return Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2) < Math.pow(radius, 2);
}

In my application, I first draw a red path, its coordinates are stored in pathArrayXand ArrayLists pathArrayY. I track the X and Y coordinates of a circular ImageView moving under the mouse, and would like to overlay the red path in the green way when the user hovers over the path from start to finish. When the user hangs over the red track, part of the red path that they have already completed will be blocked by the green track along the same segment. Coordinates X and Y ImageView ( curXand curY) are calculated from the current stream.

However, my application does not seem to draw the green path at all. Am I doing something wrong here?

+4
1

?

, onDraw (Canvas), , . , pathIndex++ , while? , for, while-loop , .

: boolean start greenPath, if (greenPath == null){ . , , , , .

+3

Source: https://habr.com/ru/post/1607032/


All Articles