0

I am trying to make an hexagonal imageview with rounded corners helped by some code I found and working with arcs to draw corners. This method is not working probably because I am doing something wrong. I hope there is an easier method, too.
This is my code for the first arc-corner, but the result is not good.

private void calculatePath(float radius) {
    float halfRadius = radius / 2f;
    float triangleHeight = (float) (Math.sqrt(3.0) * halfRadius);
    float centerX = getMeasuredWidth() / 2f;
    float centerY = getMeasuredHeight() / 2f;

    this.hexagonPath.reset();
    this.hexagonPath.moveTo(centerX, centerY + radius);
    this.hexagonPath.lineTo(centerX - triangleHeight / 4f * 3f, centerY + radius / 8f * 5f);
    this.hexagonPath.arcTo(new RectF(centerX - triangleHeight, centerY + radius / 8f * 5f, centerX - triangleHeight / 4f * 3f, centerY + halfRadius / 2f), 30f, 180f);
    this.hexagonPath.lineTo(centerX - triangleHeight, centerY - halfRadius);
    this.hexagonPath.lineTo(centerX, centerY - radius);
    this.hexagonPath.lineTo(centerX + triangleHeight, centerY - halfRadius);
    this.hexagonPath.lineTo(centerX + triangleHeight, centerY + halfRadius);
    this.hexagonPath.close();

    invalidate();
}

This is the result where as you can see there isn't any arc:

Please help me finding a solution or an easier method.

Also please don't link me libraries, I want to do this by myself for my app.

Sorry for my English, not my main language.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Giorgio
  • 65
  • 10
  • You can find the answer here: https://stackoverflow.com/questions/22601400/how-to-give-hexagon-shape-to-imageview – Suraj Vaishnav May 20 '18 at 09:37
  • @SurajVaishnav I've already read that but it isn't helpful for drawing an hexagon with rounded corners... just a rectangle that is really much easier. – Giorgio May 20 '18 at 09:50

0 Answers0