android - 运动布局不应用窗口插图

标签 android android-motionlayout windowinsets

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/

相关文章:

android - 如何将插图应用于内部有图像的 CollapsingToolbarLayout,以便工具栏中的图像绘制在状态栏后面?

android - 如何使用改造将成功的响应主体转换为特定类型?

java - 在 Android 中重复写入 XML 文件的最有效方法是什么?

flutter - 如何在Flutter中实现自定义应用栏布局可滚动效果

Android:MotionLayout 不允许 child 展开并填满屏幕

android - OnApplyWindowInsetsListener 给出始终为 0 的 systemWindowInsetBottom

android - 使用最新的 WindowInset API 出现软键盘时如何调整对话框布局

android - 为什么 ListView.getCheckedItemPositions() 没有返回正确的值?

android - 与奥托一起改造 - 订阅未调用

android - RecyclerView 为其项目设置了错误的 MotionLayout 状态