LayoutInflater.inflate简易的使用说明记录
16lz
2021-01-23
LayoutInflater它主要是用于Android加载布局。基本用法:LayoutInflater layoutInflater=LayoutInflater.from(this);View view=layoutInflater.inflate(R.layout.activity_test01_item01,rl,false);rl.addView(view);
LayoutInflater.inflate()有三个参数分别为:
将要加载的布局id
指定将要加载到的父布局(可以为null)
是否加载到父布局(true/false)
参数不同的几种情况:
如果第三个参数为null则意思是不加载到父布局,在页面上不会显示要添加的布局,除非接上一句 rl.addView(view);
如果第二个参数指定了父布局,则正常加载
如果第二个参数未指定父布局(null),使用rl.addView(view)也可以加载布局到页面,但是,加载布局的最外层layout属性失效
12.11更新
addView()的三个参数
Parameters | |
---|---|
child | View : the child view to add
|
index | int : the position at which to add the child or -1 to add last
|
params | ViewGroup.LayoutParams : the layout parameters to set on the child |
子布局,子布局位置(-1表示线性布局中置于底部,0表示置于顶部,如果多个view重叠,则index越大,该view则越处于上层),添加子布局的父布局参数(如果有原父布局,则原父布局参数失效)
更多相关文章
- Android调用系统相机onActivityResult返回参数data为null
- Android 四大组件+五大布局
- 在Android平台上加载本地库的危险性
- android 动态设置布局
- 新浪微博布局学习——活用Android的RelativeLayout
- android分开布局
- android 布局之滑动探究 scrollTo 和 scrollBy 方法使用说明
- Android实现加载等待展示
- android intent activity参数传递