LayoutInflater和inflate()方法的使用方法

    public static LayoutInflaterfrom(Context context) {

        LayoutInflaterLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if(LayoutInflater== null){

            thrownew AssertionError("LayoutInflaternot found.");

        }

        returnLayoutInflater;

    }

能够看出它事实上调用context.getSystemService()。

 

 

public View inflate(int Resourece,ViewGrouproot)
作用:填充一个新的视图层次结构从指定的XML资源文件里
reSource:View的layout的ID
root: 生成的层次结构的根视图
return 填充的层次结构的根视图。假设參数root提供了,那么root就是根视图;否则填充的XML文件的根就是根视图。

其余几个重载的inflate函数类似。



posted @ 2014-10-12 20:36  blfshiye  阅读(138)  评论(0编辑  收藏  举报