gpt4 book ai didi

kotlin - onApplyWindowInsets(WindowInsets insets) 没有被调用

转载 作者:行者123 更新时间:2023-12-02 12:47:15 25 4
gpt4 key购买 nike

我目前正在使用扩展约束布局的自定义 View ,但它不会在 View onApplyWindowInsets(WindowInsets insets) 中触发此覆盖方法,不确定丢失了什么。

  class TestCustomView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {


init {


}
//This method one not get called
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
return super.onApplyWindowInsets(insets)
val statusBarHeight = insets.systemWindowInsetTop
}


override fun fitSystemWindows(insets: Rect): Boolean {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
// Intentionally do not modify the bottom inset. For some reason,
// if the bottom inset is modified, window resizing stops working.
insets.left = 0
insets.top = 0
insets.right = 0
}
return super.fitSystemWindows(insets)
}


}

最佳答案

一旦 insets 被消耗,沿层次结构的传播就会停止。看起来更高的东西正在消耗可用的东西。见 isConsumed() 窗口插入 .

Check if these insets have been fully consumed.

Insets are considered "consumed" if the applicable consume* methods have been called such that all insets have been set to zero. This affects propagation of insets through the view hierarchy; insets that have not been fully consumed will continue to propagate down to child views.

关于kotlin - onApplyWindowInsets(WindowInsets insets) 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55487471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com