0

以下 LayoutInflater 有什么区别,这是最有效的方法。

  1. LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.buttons,null);

  2. View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.buttons,null);

  3. View view = getLayoutInflater().inflate(R.layout.buttons, mainLayout,false);

4

1 回答 1

0

所有 3 种方法在内部都做同样的事情。他们打电话

LayoutInflater  inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

但是getLayoutInflater()会为您提供创建窗口时使用的缓存 LayoutInflator,而不是getSystemService每次都调用,但不确定它是否会提供任何显着的性能激励,尽管可能会快一点。

于 2012-10-20T08:12:45.400 回答