android中获取布局文件的三种方法

阅读 25

2023-09-04


android中获取布局文件的三种方法

R.layout.item 为定义的布局文件(通过一个打气筒把布局文件转换成一个view)

第一种:

view = View.inflate(getApplicationContext(), R.layout.item, null);

第二种:

LayoutInflater inflater = LayoutInflater.from(getApplicationContext());

view = inflater.inflate(R.layout.item, null);

第三种:

LayoutInflater  inflater  =  getSystemService(LAYOUT_INFLATER_SERVICE);

view  =  inflater.inflate(R.layout.item, null);

精彩评论(0)

0 0 举报