获取LayoutInflater的方法有如下三种:
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main,
null
);
LayoutInflater inflater = LayoutInflater.from(context); (该 方法实质就是第一种 方法,可参考源 代码)
@H_ 404_35@);
@H_404_35@LayoutInflater inflater = getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)
);
|
使用方法:
public
class
MyInflate
extends
Activity{
private
TextView tv;
void
OnCreate(Bundle savedInstanceState){
super
.onCreate(savedInstanceState);
//setContentView(R.layout.main);
//tv = (TextView) findViewById(R.id.tv);
@H_404_35@LayoutInflater inflate = LayoutInflater.from(
this
View view = inflate.inflate(R.layout.main,monospace!important; white-space:pre-wrap; float:none!important; border-top-width:0px!important; border-bottom-width:0px!important; height:auto!important; color:#000000!important; font-size:12px!important; vertical-align:baseline!important; border-left-width:0px!important; top:auto!important; right:auto!important; padding-top:0px!important; left:auto!important">setContentView(view);
@H_404_35@}
}
原文链接:https://www.f2er.com/xml/299839.html