怎么在Jetpack Compose中制作虚线/虚线?
本教程将介绍如何在Jetpack Compose中制作虚线/虚线?的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。
问题描述
我需要从this answer复制Android XML视图,但在Jetpack中用纯Kotlin合成
推荐答案
只需使用Canvas
方法drawLine
应用为pathEffect
aPathEffect.dashPathEffect
:
val pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f)
Canvas(Modifier.fillMaxWidth().height(1.dp)) {
drawLine(
color = Color.Red,
start = Offset(0f, 0f),
end = Offset(size.width, 0f),
pathEffect = pathEffect
)
}
您还可以将相同的路径效果应用于其他方法:
val stroke = Stroke(width = 2f,
pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f)
)
Canvas(Modifier.fillMaxWidth().height(70.dp)){
drawRoundRect(color = Color.Red,style = stroke)
}
好了关于怎么在Jetpack Compose中制作虚线/虚线?的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。