android 在 onCreate 方法中获取可绘制区域
如果我有一个高度和宽度为 fill_parent 的布局,有没有办法在 onCreate 方法中获取他的高度和宽度?如果没有,他的尺寸什么时候可用?我需要这个,因为我需要在运行时添加一些视图,并且我需要知道有多少视图填充布局。
if I have a layout with fill_parent at height and width, is there a way to get his height and width in onCreate method? if not, when his dimensions are available? I need this because I need to add at runtime some views and I need to know how many views fill in the layout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:。
假设您在 onCreate 方法中有布局视图
You can do that:.
Suppose you have the layout view in onCreate method
您可以使用
onSizeChanged
方法在计算后获取信息,但这也可能有助于至少获取显示的尺寸。您可能会发现这很有用:
何时调用 onSizeChanged()?
You can use the
onSizeChanged
method to get the information when it has been calculated, but this may also help to at least get the dimensions of the display.You may find this useful:
when is onSizeChanged() called?