android - 重叠绘图
问题描述
我的底层覆盖了他的绘制方法。底层子类约束布局
override fun draw(canvas: Canvas?) {
super.draw(canvas)
val timePoints = getTimeRepresentation()
var x: Float
var y: Float
// Draw Bottom Buffer
//y = height - bottomBufferHeight
canvas!!.drawRect(0f, height - bottomBufferHeight, width.toFloat() + converter.convertDpToPixel(2f), height.toFloat(), bufferPaint)
// Draw Top Buffer
y = topBufferHeight
canvas.drawRect(0f, 0f, width.toFloat(), y, bufferPaint)
val heightOfHour = actualHeightOfHour()
val textHeightOffset = textPaint.textSize /3
// Draw Hours & Lines
x = padding
y += heightOfHour
for (i in 0..23) {
// Draw TimeText
canvas.drawText(timePoints[i], x, y + textHeightOffset, textPaint)
// Draw Line
x += timeWidth + padding
canvas.drawLine(x, y, width - padding, y, linePaint)
// Set X, Y for next run
x = padding
y += heightOfHour
}
}
使用初始化程序:
linePaint = Paint()
linePaint.color = resources.getColor(R.color.chronoView_line)
linePaint.strokeWidth = converter.convertDpToPixel(1f)
linePaint.isAntiAlias = true
textPaint = Paint()
textPaint.color = resources.getColor(R.color.inactive_on)
textPaint.textSize = converter.convertDpToPixel(14f)
textPaint.isAntiAlias = true
bufferPaint = Paint()
bufferPaint.color = resources.getColor(R.color.buffer_pale)
bufferPaint.isAntiAlias = true
然后我在该视图的顶部添加了其他一些视图,但线 (linePaint) 绘制在这些视图的顶部,如下所示
链接:https ://ibb.co/fvdyjDC 备用链接:https ://i.ibb.co/ySFZH48/Screen-Shot-2019-09-15-at-9-30-57-PM.png
蓝线是一个单独的视图,它是这个子类 ConstraintLayout 的子视图,同样适用于这些 New Task 视图,它们之间在它们上面画了线......
我不明白是什么原因造成的,有人有什么想法吗?
解决方案
推荐阅读
- pattern-matching - Elixir 模式匹配解释
- c# - 在 c# 中解压缩 gz 文件:System.IO.InvalidDataException:'存档条目是使用不受支持的压缩方法压缩的。'
- flutter - 未来
- >>' 不能分配给参数类型 'List
- python - Python 中用于导入的默认参数
- javascript - javascript中的作用域链和全局对象
- python - 如何从 Python 制作作为另一个 C 函数和 Python 函数参数的闭包的 C 函数指针
- python - 通过遍历pygame中的列表来创建地图?
- node.js - Google App 引擎自定义运行时 - 主机标头无效
- python - 无法修复错误:ListVector 类型的对象在烧瓶上不是 JSON 可序列化的?
- javascript - 创建html