I want to draw a custom view , 
in this image I need to draw rounded corners of the rectangle
I wrote this code
class RoundedRectUsingPath @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val roundCorner = 10f
private val paint = Paint().apply {
color = Color.RED
isAntiAlias = true
pathEffect = CornerPathEffect(roundCorner)
setShadowLayer(10f, -2f, 2f, android.graphics.Color.BLACK)
}
private var path = Path()
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
val left = 10f
val top = 0f
val avatarRadius = 30f
val shapeBounds = RectF(left, top+20, left + width - 40, top + height -20)
val leftCutoutPoint = PointF(left, shapeBounds.bottom/2)
val rightCutOutBounds = PointF(shapeBounds.right, shapeBounds.bottom/2)
val leftAvatarBounds = fromCircle(center = leftCutoutPoint, radius = avatarRadius)
val rightAvatarBounds = fromCircle(center = rightCutOutBounds, radius = avatarRadius)
path = Path().apply {
moveTo(shapeBounds.left, shapeBounds.top)
arcTo(leftAvatarBounds, -90f, 180f, false)
lineTo(shapeBounds.bottomLeft.x, shapeBounds.bottomLeft.y)
lineTo(shapeBounds.bottomRight.x, shapeBounds.bottomRight.y)
arcTo(rightAvatarBounds, 90f, 180f, false)
lineTo(shapeBounds.topRight.x, shapeBounds.topRight.y)
close()
}
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawPath(path, paint)
}
fun fromLTRB(left: Float, top: Float, right: Float, bottom: Float) =
RectF(left, top, right, bottom)
fun fromLTWH(left: Float, top: Float, width: Float, height: Float) =
fromLTRB(left, top, left + width, top + height)
fun fromCircle(center: PointF, radius: Float) =
fromCenter(
center = center,
width = radius,
height = radius
)
fun fromCenter(center: PointF, width: Float, height: Float) =
fromLTRB(
center.x - width,
center.y - height,
center.x + width,
center.y + height
)
fun RectF.inflate(delta: Float): RectF {
return fromLTRB(
left - delta,
top - delta,
right + delta,
bottom + delta
)
}
}
but when I am using pathEffect = CornerPathEffect(roundCorner). where round corner is 10fthe image is changing to this 
Here you can see the cutout shape changes, which is not expected.
And the topleft corner is not perfectly round but a straight line between 2 points.
The expected is rounded corners with perfect cutouts, I tried many different ways to acheive this but none of them are working for me.
It looks like you have two issues:
This looking buggy to me. Maybe someone will have a more direct fix, but I recommend that you take a look at MaterialShapeDrawable to draw your shape.
Here is some more information on MaterialShapeDrawable. It looks like the "ticket" shape is what you are looking for.
From your update to the questions:
This still looks like a bug to me. However, if you add one to
leftAvatarBounds.top += 1, the left cutoff will be correct. Why? I don't know. AddingrightAvatarBounds.bottom += 1to the right cutoff works for that side.Do not start the path in a corner but within one side.
You can get your code working by changing the path calculation to the following:
This is what is displayed with the above changes:
Although this works, you may not feel comfortable, as I would not, relying upon the magical addition of one to the avatar bounds.
I went ahead and coded up a MaterialShapeDrawable which I mentioned would be an alternate solution:
This displays as follows: