我目前正在使用扩展Constraint布局的自定义视图,但我不会在视图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)
}
}
一旦使用了插图,就会停止向下传播。看起来更高的东西消耗了可用的东西。请参阅WindowsInset的isConsumed()
。
检查这些插入是否已完全消耗。
如果已调用适用的消耗*方法使得所有插入都设置为零,则认为插入被“消耗”。这会影响通过视图层次结构传播插图;尚未完全消耗的插入将继续传播到子视图。