Android LayoutInflater的inflate方法中attachToRoot的作用
来源:互联网 发布:网络招商怎么做 编辑:程序博客网 时间:2024/05/10 21:40
我们在ListView的Adapter的getView方法里面经常会调用两个参数的inflate方法,
我们可能会发现layout外层的layout_width layout_height属性都没起作用,全都变成wrap_content的值了。
这个问题就是因为我们使用了错误的参数照成的, 系统在inflate layout的时候 如果传入的root为空的话 就会忽略LayoutParams.
所以在getView里面应该调用
这样在R.layout.adv_viewpager layout xml文件里面所有关于Layout的属性就都能生效。
那么attachToRoot是什么作用呢? 他会自动把layout加到View hierarchy中, 不需要手动调用root.addView,当然在Adapter.getView里面不用手动调用root.addView是因为Adapter已经帮我们做了, 所以如果我们在Adapter.getView里面传入attachToRoot为true的话,就会报错, 因为一个view不能attach两次。
- mInflater.inflate(R.layout.adv_viewpager, null)
我们可能会发现layout外层的layout_width layout_height属性都没起作用,全都变成wrap_content的值了。
这个问题就是因为我们使用了错误的参数照成的, 系统在inflate layout的时候 如果传入的root为空的话 就会忽略LayoutParams.
所以在getView里面应该调用
- mInflater.inflate(R.layout.adv_viewpager, root, false)
这样在R.layout.adv_viewpager layout xml文件里面所有关于Layout的属性就都能生效。
那么attachToRoot是什么作用呢? 他会自动把layout加到View hierarchy中, 不需要手动调用root.addView,当然在Adapter.getView里面不用手动调用root.addView是因为Adapter已经帮我们做了, 所以如果我们在Adapter.getView里面传入attachToRoot为true的话,就会报错, 因为一个view不能attach两次。
0 0
- Android LayoutInflater的inflate方法中attachToRoot的作用
- Android LayoutInflater的inflate方法中attachToRoot的作用
- Android LayoutInflater的inflate方法中attachToRoot的作用
- 【Android 界面效果43】Android LayoutInflater的inflate方法中attachToRoot的作用
- Android LayoutInflate.from(...).inflate(...,boolean attachToRoot)方法中attachToRoot参数的意义
- Android:LayoutInflater的inflate方法
- 关于LayoutInflater类inflate(intresource, ViewGroup root, boolean attachToRoot)方法三个参数的含义
- LayoutInflater 的inflate(int resource, ViewGroup root, boolean attachToRoot)方法研究
- 关于LayoutInflater类inflate(intresource, ViewGroup root, boolean attachToRoot)方法三个参数的含义
- LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的使用
- Android LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的参数理解
- Android LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的参数理解
- Android编程之LayoutInflater的inflate方法详解及其中参数的作用
- LayoutInflater.inflate()之attachToRoot
- LayoutInflater的inflate方法
- LayoutInflater的inflate方法
- LayoutInflater的inflate方法
- Android编程之LayoutInflater的inflate方法
- Java表达式类型自动提升
- 括号配对
- javaEE__jsp
- javaEE__JSP指令
- nyoj 20 吝啬的国度
- Android LayoutInflater的inflate方法中attachToRoot的作用
- The.Strain血族
- Cookie和Session详细介绍
- rsync配合ssh在不稳定网络下传输大文件
- 《C++primer(第五版)》学习之路-第十章:泛型算法
- 面试问题背后的“猫腻”
- Unity 资源打包Assetbundle
- FPGA初步-Verilog的乘法器
- 从IT菜鸟变为“IT骨干开发者”的11个建议