Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addStatusBarTopPadding高度问题 #32

Closed
xilost opened this issue May 17, 2021 · 6 comments
Closed

addStatusBarTopPadding高度问题 #32

xilost opened this issue May 17, 2021 · 6 comments

Comments

@xilost
Copy link

xilost commented May 17, 2021

internal fun View.addStatusBarTopPadding() {
setPadding(paddingLeft, paddingTop + statusBarHeight, paddingRight, paddingBottom)
val lp = layoutParams
if (lp.height != ViewGroup.LayoutParams.MATCH_PARENT && lp.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
lp.height += statusBarHeight
layoutParams = lp
return
}
post {
lp.height = height + statusBarHeight
layoutParams = lp
}
}

addStatusBarTopPadding这个方法if+post里执行的都一样,你想排除WRAP_CONTENT和MATCH_PARENT的情况不就失效了吗?目前我的布局height是WRAP_CONTENT,就多加了statusBarHeight。

@Zackratos
Copy link
Owner

这个 if 不是为了排除 WRAP_CONTENT和MATCH_PARENT的情况的,而是因为 WRAP_CONTENT和MATCH_PARENT的情况下,View 高度是不确定的,所以必须在 post 中等 view 的高度确定之后再加上 StatusBar 的高度,另外,这个方法是为了在需要的情况下给 View 增加一个 StatusBar 的高度的,如果不需要,就不用调用这个方法

@xilost
Copy link
Author

xilost commented May 18, 2021

@Zackratos
我就是需要View增加一个StatusBar ,但是这个方法paddingTop + statusBarHeight,然后lp.height = height + statusBarHeight,这样就是增加了两个StatusBar了。

@Zackratos
Copy link
Owner

好像确实有这个问题,我下个版本尝试修复一下

@zhaoxiuyu
Copy link

@Zackratos 如果使用了 AdaptScreenUtils 适配, addStatusBarTopPadding这个方法状态栏的高度是不对的。

@Zackratos
Copy link
Owner

@Zackratos 如果使用了 AdaptScreenUtils 适配, addStatusBarTopPadding这个方法状态栏的高度是不对的。

这时因为获取到的状态栏高度不对,跟这里说的不是同一个问题,这个属于 issues 29 的问题,可以关注那个 issues

@Zackratos
Copy link
Owner

问题已解决,可以使用 0.6.1 版本
@xilost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants