Код: Выделить всё
class CustomCurvedView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val paint = Paint().apply {
color = 0xFF4CAF50.toInt()
style = Paint.Style.FILL
isAntiAlias = true
}
private val path = Path()
private val cornerRadius = 50f
private val curveHeight = 100f
private val curveWidth = 200f
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val width = width.toFloat()
val height = height.toFloat()
val roundedRect = RectF(0f, 0f, width, height - curveHeight)
path.reset()
path.addRoundRect(roundedRect, cornerRadius, cornerRadius, Path.Direction.CW)
path.moveTo(width / 2 - curveWidth / 2, height - curveHeight)
val x1 = width / 2
val y1 = height
val x2 = width / 2 + curveWidth / 2
val y2 = height - curveHeight
path.cubicTo(
width / 2 - curveWidth / 4, height, // Control point 1
width / 2 + curveWidth / 4, height, // Control point 2
x2, y2 // End point
)
path.lineTo(width, height - curveHeight)
path.lineTo(0f, height - curveHeight)
path.close()
canvas.drawPath(path, paint)
}
}
Как я могу заархивировать более гладкую форму, как прикреплено.
Я хочу чтобы получить результат, подобный изображению
Я попробовал прикрепленный код, и он выглядит, как показано ниже, кривая внизу должна быть более плавной
Подробнее здесь: https://stackoverflow.com/questions/791 ... using-path