# Base Solution

## OnMeasure

`override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {    val fixedL = l + paddingLeft    val fixedT = t + paddingTop    val fixedR = r - paddingRight    val fixedB = b - paddingBottom    when(childCount) {        1 -> layoutOneChild(fixedL, fixedT, fixedR, fixedB)        2 -> layoutTwoChildren(fixedL, fixedT, fixedR, fixedB)        else -> layoutTreeChildren(fixedL, fixedT, fixedR, fixedB)    }}`

# 👍Boost 1️⃣: Extrapolate it for any child count

## Concept of algorithm

`weight[i] = (view[i].height + view[i + 1].height) / 2weight[0] = view[0].height + view[1].height / 2weight[n - 2] = view[n - 2].height / 2 + view[n - 1].height`
`totalHeight = children.sum { it.height }`

# 👍Boost 2️⃣: Add offsets

## Implementation

`private class Bucket(    val filled: Float,    val scales: Float,    val position: Int)`

# Afterwords

Love being creative to solve some problems with an simple and elegant ways

## More from Michael Spitsin

Love being creative to solve some problems with an simple and elegant ways