2017-02-19 7 views
0

Хочет спросить. В чем разница между:Разница в раздувании просмотров

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

И:

LayoutInflater layoutInflater = LayoutInflater.from(this); 

?

+0

Там нет никакой разницы, проверьте 'от' исходный код – Selvin

+0

@Selvin, могли бы вы поделиться со мной? –

+0

Зачем? Android - это open source, и его можно легко найти. – 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

Смежные вопросы