一.打气筒(inflate)三种实现方式
打气筒的作用是将一个布局转化为一个view对象
1.
View inflate = View.inflate(MainActivity.this, R.layout.layout_item, null); //第三个参数是表示是否添加到ViewGroup里面`
- 1
- 2
- 3
2.
View inflate = LayoutInflater.from(getApplication()).inflate(R.layout.layout_item, null);- 1
3.
LayoutInflater systemService = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View inflate = systemService.inflate(R.layout.layout_item, null);- 1
- 2
本文介绍了在Android中使用打气筒(inflate)方法的三种实现方式,这些方法用于将布局文件转换为View对象。具体包括:1. 使用当前Activity进行inflate;2. 通过LayoutInflater服务实现;3. 利用系统服务LAYOUT_INFLATER_SERVICE进行inflate操作。
202

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



