1) View view = LayoutInflater.from(context).inflate(要装载的界面的id, 根节点);//context为this,根节点一般为null
view.findViewByID();//与inflate配套使用的。
setContentView();//配套使用findViewByID(动态界面中的控件的id);
2) LayoutInflater inflater = ((Activity)context).getLayoutInflater();
3) 另一种方法获得
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVER);
view = inflater.inflater (resource, root);
4)view = View.inflate(context, R.layout.header, null);
版权所有,转载请注明出处!http://blog.youkuaiyun.com/kuailebeihun_/article/details/22992685
本文详细介绍了在Android开发中如何使用LayoutInflater来加载布局文件,并通过不同的方法实例化视图对象。文中提供了多种LayoutInflater的使用方式,包括通过Context获取LayoutInflater服务、直接使用View.inflate方法等。
935

被折叠的 条评论
为什么被折叠?



