Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motion layout does not apply window insets

ViewCompat.setOnApplyWindowInsetsListener(fab) { view, insets ->
        val lp = fab.layoutParams as ConstraintLayout.LayoutParams
        lp.bottomMargin += insets.systemWindowInsetBottom
        fab.layoutParams = lp
        insets
    }

Motion layout does not pass any window insets to children in spite of consuming the insets explicit in the OnApplyWindowInsetsListener listener.

The insets are applied correctly when applyMotionScene attribute of motion layout is set to false.

like image 487
Smith Shelke Avatar asked Aug 31 '25 02:08

Smith Shelke


1 Answers

with(ml) { //ml -> your motionLayout id
                    updateState(R.id.start, ConstraintSet().apply {
                        clone(ml)
                        constrainHeight(viewWhichHeightNeedsToChange.id, height.dp + insets.systemWindowInsetTop)
                        applyTo(ml)
                    })
                    setState(R.id.end, ml.width, ml.height)
                    updateState(R.id.end, ConstraintSet().apply {
                        clone(ml)
                        constrainHeight(viewWhichHeightNeedsToChange.id, height.dp + insets.systemWindowInsetTop)
                        applyTo(ml)
                    })
                    setState(R.id.start, ml.width, ml.height)
                }

Basically you need to update padding/size of your views in both motion layout sets. Would be great if there is a way to do so without switching between states though. This code is executed in setOnApplyWindowInsetsListener { } works with

androidx.constraintlayout:constraintlayout:2.0.0-beta3

like image 128
Denis Rudenko Avatar answered Sep 03 '25 04:09

Denis Rudenko