Slide 19
Slide 19 text
override fun onDraw(c: Canvas, parent: RecyclerView,
state: RecyclerView.State) {
…
(0 until parent.childCount)
.mapNotNull(parent::getChildAt)
.windowed(2, step = 2, partialWindows = true)
.forEach {
val text = "HH:mm"
val top = it.first().top.toFloat() + margin
val centerX = width / 2f
val baseX = centerX - textPaint.measureText(text) / 2
val textBounds = Rect()
.apply { textPaint.getTextBounds(text, 0, text.length - 1, this) }
val baseY = top + textBounds.height()
c.drawText(text, baseX, baseY, textPaint)
c.drawLine(centerX, top + textBounds.height() + margin,
centerX, it.last().bottom.toFloat(), linePaint)
}
}
Timeline