如何知道什么时候活动奠定了? [英] How to know when activity is laid out?

查看:82
本文介绍了如何知道什么时候活动奠定了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了我想要把一些标记之上一个图形页面。我会从我开始的活动web服务检索这些,所以我需要知道当前视口的最小和最大纬度/经度对。我打电话

I've got a mapview that I want to put some markers on top of. I'll retrieve these from a webservice when I start the activity, so I need to know the minimum and maximum lat/lng pairs for the current viewport. I'm calling

mMapView.getWidth()
mMapView.getHeight()

但他们都返回0,而活动正在启动。我试图把它onAttachedToWindow,onResume,onPostCreate,onPostResume,在onStart等,但都无济于事。我怎么能知道该活动已完成铺设了各方面的意见,并准备给我正确的高度和宽度测量?

But they both return 0 while the activity is starting. I tried putting it in onAttachedToWindow, onResume, onPostCreate, onPostResume, onStart and so on, but to no avail. How can I know that the activity has finished laying out all the views and is ready to give me the correct height and width measurements?

推荐答案

我认为你必须重写<一个href=\"http://developer.android.com/reference/android/view/View.html#onSizeChanged%28int,%20int,%20int,%20int%29\"相对=nofollow> onSizeChanged 并从那里调用的getWidth /高度。要知道,虽然你的活动的生命周期(的看法改变每次的大小)期间onSizeChanged可能会被多次调用。

I think you have to override onSizeChanged and call getWidth/Height from there. Be aware though that onSizeChanged might get called multiple times during your activity's lifecycle (Everytime the size of the view changes).

这篇关于如何知道什么时候活动奠定了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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