在Android中需要加载布局时,我们需要系统的布局填充器,来加载布局。
可以使用以下几种方式加载布局:
方式1:
LayoutInflater inflater = LayoutInflater.from (this);
View view = inflater.inflate (R.layout.activity_main, null);
方式2:
LayoutInflater layoutInflater = (LayoutInflater) getSystemService (LAYOUT_INFLATER_SERVICE);
View view1 = layoutInflater.inflate (R.layout.activity_main, null);
方式3:
View v = View.inflate (this, R.layout.activity_main, null);