CustomShape с использованием Java в Android Studio

1
7

Я пытаюсь создать CustomShape, но у меня возникла проблема. Вот чего я хочу добиться, а вторая картинка — то, что у меня есть сейчас:

Ссылка на изображение, которую я хочу

Результат, который я сейчас имею в Android Studio

Вот мой code:

Любые идеи, как это исправить, приветствуются. Заранее спасибо.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float width = getWidth();
    float height = getHeight();
    float cornerRadius = 50f; // Adjust for the rounded corners
    float cutoutRadius = width * 0.10f; // Radius of the semicircular cutout



path.reset();

    // Start at the top-left corner
    path.moveTo(cornerRadius, 0);
path.lineTo(width - cornerRadius, 0);
    path.quadTo(width, 0, width, cornerRadius);

    // Draw the right edge
    path.lineTo(width, height - cornerRadius);
    path.quadTo(width, height, width - cornerRadius, height);

    // Draw the bottom-right straight line
    path.lineTo(width / 2 + cutoutRadius, height);

    // Draw the semicircle in the center of the bottom edge
    path.arcTo(width / 2 - cutoutRadius, height - cutoutRadius * 2, width / 2 + cutoutRadius, height, 0, -180, false);

    // Draw the bottom-left straight line to complete the bottom edge
    path.lineTo(cornerRadius, height);
    path.quadTo(0, height, 0, height - cornerRadius);

    // Draw the left edge
    path.lineTo(0, cornerRadius);
    path.quadTo(0, 0, cornerRadius, 0);

    // Close the path
    path.close();

    // Draw the path on the canvas
    canvas.drawPath(path, paint);
}
Гаврила
Вопрос задан23 мая 2024 г.

1 Ответ

Ваш ответ

Загрузить файл.