Android various layout description of detailed usage and stuffer

1. The acquisition system layout manager through the system, this approach is generally used when we obtain associated operating system and applications or systems

 LayoutInflater inflater=(LayoutInflater)Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);如Activity may be omitted if the Context, if necessary in the context of a class;

View mView=inflater.inflate(Context,R.layout.XX,root);

2. Use the following manner when added to give a ViewGroup sub-layout in an Activity

View  mView=getLayoutInflate.inflate(R.layout.xx,root,false);

3. By acquiring static View, which is usually used in custom controls, such as a custom dialog or toast can be used in

View mView=View.inflate(Context,R.layout.xx,false);

4, through the LayoutInflate inflate () method is implemented, the layout of a typical embodiment of the loading BaseAdapter

View view=LayoutInflater.from(Context).inflate(R.layout.xx,rootView,false);

These are the four kinds of usage Layoutinflate. Simply by speaking about the difference between bar codes or the nature of the relationship between the following four

First: In an Activity,

public  Layoutinflater getLayoutInflater(){

return getWindow().getLayoutInflater();}

 The Activity at the bottom or call the Window class abstract method:

 public LayouInflater getLayoutInflater(Context context){

return  LayoutInflate.from(Context context);

}, While the window class is how to call it? Consider the following content

Window is to get through the static way LayoutInflater

 public   static  View  inflate(Context mContext, LayoutRes  res, ViewGroup root){

LayoutInflater  mLayoutInflater=LayoutInflater.from(mContext);

return mLayoutInflater.inflate(res,root);

}

It is noteworthy that LayoutInflater is also an abstract class, it is ultimately the way to get the call system

public abstract  LayoutInflater  extends Object{

public static  static  LayoutInflater from(Context mContext){

 LayoutInflater mLayoutInflater=(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if(mLayoutInflater==null){

throws  Exception(Exception e);

}

return  mLayoutInflater;





}

Released eight original articles · won praise 4 · views 10000 +

Guess you like

Origin blog.csdn.net/honey_angle_first/article/details/70258734