2017-02-19 4 views
0

質問したいと思っています。ビューの膨張の違い

LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

そして:

LayoutInflater layoutInflater = LayoutInflater.from(this); 

の違いは何ですか?

+0

違いはありません、あなたは私と一緒にそれを共有することができ、 'from'ソースコード – Selvin

+0

@Selvinをチェック! –

+0

何のために? Androidはopensourceであり、簡単に見つけることができます。 – Selvin

答えて

0

違いはそれほど大きくありません。 LayoutInflater#from(Context context)ソースコード:

public static LayoutInflater from(Context context) { 
     LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     if (LayoutInflater == null) { 
      throw new AssertionError("LayoutInflater not found."); 
     } 
     return LayoutInflater; 
    } 

だから、LayoutInflater#from内部は同じcontext.getSystemServiceを使用しています。

参考:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/view/LayoutInflater.java#LayoutInflater.from%28android.content.Context%29

関連する問題