首页 > 解决方案 > 重叠绘图

问题描述

我的底层覆盖了他的绘制方法。底层子类约束布局

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 视图,它们之间在它们上面画了线......

我不明白是什么原因造成的,有人有什么想法吗?

标签: androidgraphicsdraw

解决方案


推荐阅读