运动布局不应用窗口插入

Smi*_*lke 3 android windowinsets android-motionlayout

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

尽管在侦听器中显式使用了插入,但运动布局不会将任何窗口插入传递给子级OnApplyWindowInsetsListener

applyMotionScene当运动布局的属性设置为时,可以正确应用插图false

Den*_*nko 6

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)
                }
Run Code Online (Sandbox Code Playgroud)

基本上,您需要更新两个运动布局集中视图的填充/大小。如果有一种方法可以在不切换状态的情况下实现这一点,那就太好了。这段代码在 setOnApplyWindowInsetsListener { } 中执行

androidx.constraintlayout:constraintlayout:2.0.0-beta3