Android 之 LayoutInflater

来源:互联网 发布:淘宝上怎么找人工客服 编辑:程序博客网 时间:2024/05/20 01:44

1.在实际开发过程中,LayoutInflater 这个类是非常有用的,它的作用类似于findViewbyId(),不同点是LayoutInflater是用来找Res/Layout/下面的xml布局文件的具体控件


2.作用:

a.对于一个没有被加载入或者想要动态加载的界面,都需要LayoutInflate() 来实现

b.对于一个已经载入的界面。可以使用findViewById()来实现


3.获得layoutInflater的三方法:

a.

LayoutInflater inflater= (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//第一个参数布局文件                View view=inflater.inflate(R.layout.ID, null);

b.

LayoutInflater inflater=LayoutInflater.from(this);                View view=inflater.inflate(R.layout.ID,null);

c.

LayoutInflater inflater= getLayoutInflater();               View view=inflater.inflate(R.layout.ID,null);


0 0
原创粉丝点击