WindowInsets与fitSystemWindow相关知识总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuanjw2014/article/details/78363353

fitSystemWindow作用

这一块的知识从名称上看出是跟系统窗口相关的,主要是状态栏和底部虚拟导航栏有关系,在4.4版本开始,Android推出了沉浸式状态栏,状态栏和导航栏变得半透明,使得用户可以对导航栏和状态栏部分进行绘制,但是在设置沉浸式模式之后,我们的用户界面部分扩展到了整个屏幕,可能会导致系统窗口遮挡用户控件的情况,fitSystemWindow就是为了解决这种问题。默认的实现是给View添加padding避开相应的系统窗口区域,在5.0及之后的版本,有了更多的灵活性。

WindowInsets介绍

inset的直译是插入物,理解为特定屏幕区域更合适一些。WindowInsets的三个成员变量mSystemWindowInsets,mWindowDecorInsets,mStableInsets表示了三种屏幕区域。

the system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.
系统窗口区域代表着整个屏幕窗口上,状态栏,导航栏,输入法等系统窗口占用的区域

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework.This can include action bars, title bars, toolbars, etc.
Decor占位区域代表着内容区域被系统框架提供的action bars, title bars, toolbars这些组件占用的区域。

该类还提供了一系列方法来获取和设置这些insets的属性getSystemWindowInsetLeft()
getSystemWindowInsetTop()
getSystemWindowInsetBottom()
consumeSystemWindowInsets()
replaceSystemWindowInsets等等。需要注意的是这里的Rect的top等属性值与通常的含义有所区别:这里的top表示的是顶部占位区域的宽度,即状态栏的宽度,长度默认是屏宽

相关资料

在MD支持包中的一些组件对WindowInsets做了处理,具体可以参考这篇文章:Why would I want to fitsSystemWindows?
中文翻译参考

猜你喜欢

转载自blog.csdn.net/yuanjw2014/article/details/78363353