应该是会多次解析,影响性能
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonClick(View v){
long startTime = System.currentTimeMillis();
for (int i = 0, length = 1000; i < length; i++) {
View view = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
}
Log.i(TAG, "during time = " + (System.currentTimeMillis() - startTime));
}
}
源代码里没有看到做缓存。
然后我写了个demo测试,1000次调用耗时1699ms, 100次调用耗时188ms