用 canvas 绘图
Draw with canvas
如何使用canvas绘制选中的蓝色背景透明色域?
在官方文档中我发现类似 this 的东西。
但是还有一个问题就是如何实现。
又比如,我试着画线:
private fun someFun(canvas: Canvas, parent: RecyclerView) {
val radius: Float = parent.context.resources.getDimension(R.dimen.dimen_12)
val paint = Paint()
paint.color = ContextCompat.getColor(parent.context, R.color.primary)
paint.style = Paint.Style.FILL
val path = Path()
path.moveTo(0f, 0f)
path.lineTo(0f, radius)
path.arcTo(RectF(0f, 0f, radius * 2, radius * 2), 270f, -90f)
path.close()
canvas.drawPath(path, paint)
}
然后得到这样的东西:
决定采用下一种方式:
private fun drawRoundedCorners(canvas: Canvas, parent: RecyclerView) {
val radius: Float = parent.context.resources.getDimension(R.dimen.dimen_12)
val paint = Paint()
paint.color = ContextCompat.getColor(parent.context, R.color.primary)
paint.style = Paint.Style.FILL
val path = Path()
path.moveTo(0f, 0f)
path.lineTo(150f, 0f)
path.arcTo(RectF(0f, 0f, radius * 2, radius * 2), 270f, -90f)
path.moveTo(parent.width.toFloat(), 0f)
path.lineTo(parent.width.toFloat(), 0f)
path.arcTo(RectF(parent.width.toFloat() - radius * 2, 0f, parent.width.toFloat(),
radius * 2), 270f, 90f)
path.close()
canvas.drawPath(path, paint)
}
如何使用canvas绘制选中的蓝色背景透明色域?
在官方文档中我发现类似 this 的东西。 但是还有一个问题就是如何实现。
又比如,我试着画线:
private fun someFun(canvas: Canvas, parent: RecyclerView) {
val radius: Float = parent.context.resources.getDimension(R.dimen.dimen_12)
val paint = Paint()
paint.color = ContextCompat.getColor(parent.context, R.color.primary)
paint.style = Paint.Style.FILL
val path = Path()
path.moveTo(0f, 0f)
path.lineTo(0f, radius)
path.arcTo(RectF(0f, 0f, radius * 2, radius * 2), 270f, -90f)
path.close()
canvas.drawPath(path, paint)
}
然后得到这样的东西:
决定采用下一种方式:
private fun drawRoundedCorners(canvas: Canvas, parent: RecyclerView) {
val radius: Float = parent.context.resources.getDimension(R.dimen.dimen_12)
val paint = Paint()
paint.color = ContextCompat.getColor(parent.context, R.color.primary)
paint.style = Paint.Style.FILL
val path = Path()
path.moveTo(0f, 0f)
path.lineTo(150f, 0f)
path.arcTo(RectF(0f, 0f, radius * 2, radius * 2), 270f, -90f)
path.moveTo(parent.width.toFloat(), 0f)
path.lineTo(parent.width.toFloat(), 0f)
path.arcTo(RectF(parent.width.toFloat() - radius * 2, 0f, parent.width.toFloat(),
radius * 2), 270f, 90f)
path.close()
canvas.drawPath(path, paint)
}