How do you know when an activity is outlined?

I have a mapview that I want to add some markers. I will extract them from the web service when I start my activity, so I need to know the minimum and maximum lat / lng pairs for the current viewport. I'm calling

mMapView.getWidth()
mMapView.getHeight()

But they both return 0 when the action begins. I tried putting it in onAttachedToWindow, onResume, onPostCreate, onPostResume, onStart etc., but to no avail. How can I find out that the activity is completed, having laid out all the looks and is ready to give me the correct measurements of height and width?

+1
source share
2 answers

, onSizeChanged getWidth/Height . , onSizeChanged ( , ).

+2

, googling:

, , . , activity.onWindowFocusChanged hasFocus = true.

:

view.onFinishInflate

view.onMeasure

view.onSizeChanged(, , 0, 0)

view.onLayout

activity.onWindowFocusChanged()

, .

, , , ViewTreeObserver, . .

+6

Source: https://habr.com/ru/post/1795874/


All Articles