ViewCompat.setOnApplyWindowInsetsListener(fab) { view, insets ->
val lp = fab.layoutParams as ConstraintLayout.LayoutParams
lp.bottomMargin += insets.systemWindowInsetBottom
fab.layoutParams = lp
insets
}
尽管在 OnApplyWindowInsetsListener
监听器中显式使用了插入,但 Motion 布局不会将任何窗口插入传递给子项。
当运动布局的 applyMotionScene
属性设置为 false
时,可以正确应用插图。
最佳答案
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)
}
基本上,您需要在两个运动布局集中更新 View 的填充/大小。如果有一种方法可以在不切换状态的情况下这样做,那就太好了。此代码在 setOnApplyWindowInsetsListener { } 中执行 与
一起工作androidx.constraintlayout:constraintlayout:2.0.0-beta3
关于android - 运动布局不应用窗口插图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59699924/