setOnApplyWindowInsetsListener从未调用 [英] setOnApplyWindowInsetsListener never called

查看:246
本文介绍了setOnApplyWindowInsetsListener从未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算NavigationBar的高度.我看过这个演示文稿: https://chris.banes.me/talks/2017/becoming-a-master-window-fitter-nyc/

I would like to calculate the navigationBar height. I've seen this presentation : https://chris.banes.me/talks/2017/becoming-a-master-window-fitter-nyc/

因此,我尝试使用方法 View.setOnApplyWindowInsetsListener().但是,由于某种原因,它从未被调用.

So, I tried to use the method View.setOnApplyWindowInsetsListener(). But, for some reason, it's never called.

有人知道为什么吗?有什么限制吗?

Does anyone knows why ? Any limitation there ?

我试图这样使用它:

navBarOverlay.setOnApplyWindowInsetsListener { v, insets -> 
   Timber.i("BOTTOM = ${insets.systemWindowInsetBottom}")
   return@setOnApplyWindowInsetsListener insets
}

请注意,我的根目录布局是 ConstraintLayout .

Note that my root layout is a ConstraintLayout.

推荐答案

我遇到了同样的问题.

如果您的根视图为ConstraintLayout且包含android:fitsSystemWindows ="true" attr,则该视图将消耗onApplyWindowInsets回调.因此,如果您在子视图上设置onApplyWindowInsets,则它们永远不会获得onApplyWindowInsets回调.

If your root view is ConstraintLayout and contains android:fitsSystemWindows="true" attr, the view consumed onApplyWindowInsets callbacks. So if you set onApplyWindowInsets on child views, they never get onApplyWindowInsets callbacks.

或者检查您的父视图是否使用了回调.

Or check your parent views consume the callback.

这篇关于setOnApplyWindowInsetsListener从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆