Android 在 Activity.onCreate() 中的 setContentView() 之后什么时候第一次调用 View.onMeasure()?
When does Android make first call to View.onMeasure() after setContentView() in Activity.onCreate()?
假设 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()
}
对 Activity 的 onCreate() 方法的调用是否保证完成执行并且 return 在 Android 首次调用任何子项的 onMeasure() 方法之前视图在 R.layout.activity_main 中声明?或者 Android 是否有权在调用 setContentView() 期间或之后随时开始调用 onMeasure()?
在 onCreate 结束时,Activity 甚至还没有出现在屏幕上(直到调用 onStart 才会出现)。因此,在此之前它不会尝试布局任何内容,因为它不在屏幕上,因此不需要布局。
假设 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()
}
对 Activity 的 onCreate() 方法的调用是否保证完成执行并且 return 在 Android 首次调用任何子项的 onMeasure() 方法之前视图在 R.layout.activity_main 中声明?或者 Android 是否有权在调用 setContentView() 期间或之后随时开始调用 onMeasure()?
在 onCreate 结束时,Activity 甚至还没有出现在屏幕上(直到调用 onStart 才会出现)。因此,在此之前它不会尝试布局任何内容,因为它不在屏幕上,因此不需要布局。