0

enter image description here

It is not a half-circle. It is an arc/bow.

Turok
  • 39
  • 1
  • 7
  • 1
    check this: https://stackoverflow.com/a/34851449/5241603 and this: https://stackoverflow.com/q/40043351/5241603 – K.Sopheak Jan 30 '23 at 06:28

1 Answers1

1

It isn't that straight forwad to design an arc in XML directly, I would maybe do that with a custom view like this one:

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF

import android.graphics.drawable.ShapeDrawable

class ArcShape(
  private val color: Int,
  private val startAngle: Float,
  private val sweepAngle: Float
) : ShapeDrawable() {
  private val rectF: RectF = RectF()
  private val shapePaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)

  init {
    shapePaint.color = color
    shapePaint.style = Paint.Style.STROKE
    shapePaint.strokeWidth = 5f
  }

  override fun draw(
    canvas: Canvas
  ) {
    canvas.drawArc(rectF, startAngle, sweepAngle, false, shapePaint)
  }

  override fun onBoundsChange(bounds: Rect) {
    super.onBoundsChange(bounds)
    rectF.set(bounds)
  }
}

The canvas is more flexible and allows you to design whatever you want! And you can do the same with Jetpack compose also!

Younes Charfaoui
  • 1,059
  • 3
  • 10
  • 20