adding helper for recalculating percentage heights within a constraint layout
- this allows percentages to be used which make of the screen viewport rather than the accumulated scroll height
This commit is contained in:
parent
b439322776
commit
2cbbfca73f
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue