加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

LayoutInflater作用是将layout的xml布局文件实例化为View类对象

发布时间:2020-12-15 23:25:59 所属栏目:百科 来源:网络整理
导读:获取 LayoutInflater 的方法有如下三种 : LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.main, null ); LayoutInflater inflater = LayoutInflater.from(c

获取LayoutInflater的方法有如下三种:

LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main, null );
LayoutInflater inflater = LayoutInflater.from(context); (该方法实质就是第一种方法,可参考源代码)
);
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);
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);
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读