mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
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
1 changed files with 17 additions and 0 deletions
|
@ -16,8 +16,12 @@
|
||||||
|
|
||||||
package im.vector.app.core.extensions
|
package im.vector.app.core.extensions
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintSet
|
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) {
|
fun ConstraintLayout.updateConstraintSet(block: (ConstraintSet) -> Unit) {
|
||||||
ConstraintSet().let {
|
ConstraintSet().let {
|
||||||
|
@ -26,3 +30,16 @@ fun ConstraintLayout.updateConstraintSet(block: (ConstraintSet) -> Unit) {
|
||||||
it.applyTo(this)
|
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 a new issue