diff --git a/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt index b1b30da156..46d173b848 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt @@ -16,8 +16,12 @@ package im.vector.app.core.extensions +import android.view.View import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet +import androidx.core.view.children +import androidx.core.view.doOnLayout +import kotlin.math.roundToInt fun ConstraintLayout.updateConstraintSet(block: (ConstraintSet) -> Unit) { ConstraintSet().let { @@ -26,3 +30,16 @@ fun ConstraintLayout.updateConstraintSet(block: (ConstraintSet) -> Unit) { it.applyTo(this) } } + +fun ConstraintLayout.realignPercentagesToParent() { + doOnLayout { + val rootHeight = (parent as View).height + children.forEach { child -> + val params = child.layoutParams as ConstraintLayout.LayoutParams + if (params.matchConstraintPercentHeight != 1.0f) { + params.height = (rootHeight * params.matchConstraintPercentHeight).roundToInt() + child.layoutParams = params + } + } + } +}