简体   繁体   English

Android什么时候在Activity.onCreate()中的setContentView()之后第一次调用View.onMeasure()?

[英]When does Android make first call to View.onMeasure() after setContentView() in Activity.onCreate()?

Suppose an Android Activity calls setCurrentView() for an XML-defined layout containing one or more Views to bind it in the usual manner: 假设一个Android Activity为一个包含一个或多个视图的XML定义的布局调用setCurrentView(),以通常的方式绑定它:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // ... other stuff
    MyCustomViewClass mcv = (MyCustomViewClass)findViewById(R.id.mcv);
    mcv.setSomeValues(x,y,z);
    // ... more stuff
    // ... ok, finished with everything in onCreate()
}

Is the call to that Activity's onCreate() method GUARANTEED to finish executing and return before Android makes its first call to the onMeasure() method for any child View declared in R.layout.activity_main? 在Android对R.layout.activity_main中声明的任何子View进行onMeasure()方法的第一次调用之前,对Activity的onCreate()方法的调用是否已确保完成执行并返回? Or is Android entitled to start making calls to onMeasure() at any time during or after the call is made to setContentView()? 还是Android有权在调用setContentView()期间或之后的任何时间开始调用onMeasure()?

At the end of onCreate the Activity isn't even on screen yet (it won't be until onStart is called). 在的onCreate结束的活动甚至没有在屏幕上,但(它不会是直到在onStart被调用)。 So it won't try to lay anything out until then, since it isn't on screen and thus doesn't need to be laid out. 因此,它不会试图打下什么,直到那时,因为它不是在屏幕上,因此不需要进行布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM