您的位置:首页 > 其它

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

2014-10-12 20:36 316 查看
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函数类似。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: