It't quite simple, all you need to do is to call super.onMeasure
after calculate the exact dimentions of yout view.
class ProportionalConstraintLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val exactWidth = 100 //do something to calculate the view widht
val exactHeight = 100 //do something to calculate the view height
setMeasuredDimension(exactWidth, exactHeight)
super.onMeasure(
MeasureSpec.makeMeasureSpec(exactWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(exactHeight, MeasureSpec.EXACTLY)
)
}
}