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 に答える