RecyclerView中item布局的"match_parent"属性失效--LayoutInflate的深入了解
来源:互联网 发布:2017学校网络改造方案 编辑:程序博客网 时间:2024/05/19 23:13
用recyclerview,给item布局使用了match_parent属性,运行后不起作用。查了下。是在onCreateViewHolder中加载布局时候出了问题。
一开始用的View.Inflate方法。查看源码后,发现View.inflate也是调用了LayoutInflat而的inflate方法 public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
而在LayoutInflater中,最后调用的是
public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) {···}
分析源码
if (root != null) { if (DEBUG) { System.out.println("Creating params from root: " + root); } // Create layout params that match root, if supplied params = root.generateLayoutParams(attrs); if (!attachToRoot) { // Set the layout params for temp if we are not // attaching. (If we are, we use addView, below) temp.setLayoutParams(params); } }
要执行setLayoutParams方法,需要root不能为空,切attachToRoot为false。感觉有空LayoutInflater还得再看一下。这里有hongyan大神的一篇讲LayoutInflater的。感觉还是得仔细看一下。
0 0
- RecyclerView中item布局的"match_parent"属性失效--LayoutInflate的深入了解
- RecyclerView的使用方法以及item布局"match_parent"属性失效
- RecyclerView控件布局的"match_parent"属性失效
- RecyclerView中的item的match_parent属性失效问题解决方案。
- RecyclerView中的item的match_parent属性失效问题解决方案
- RecyclerView item中match_parent失效
- RecyclerView的列表布局中match_parent失效的解决方法
- 解决 RecyclerView item布局的match_parent无效
- RecyclerView控件列表项布局match_parent属性失效的根本原理
- RecyclerView控件列表项布局match_parent属性失效的根本原理
- 关于自定义Dialog 中match_parent 属性 失效的问题
- RecyclerView的深入了解
- RecyclerView的item根布局中的Layout_xxx属性不起作用
- RecycleView添加条目布局match_parent失效的问题
- ListView中item的最外层使用margin属性失效
- ListView中item的最外层使用margin属性失效
- ListView中item的最外层使用margin属性失效
- 动态改变recyclerview的item的布局
- MyBatis学习四 懒加载和缓存
- L2-011. 玩转二叉树
- 数据结构之二叉排序树
- MaxCompute(原ODPS) MapReduce常见问题解答
- hadoop第二天
- RecyclerView中item布局的"match_parent"属性失效--LayoutInflate的深入了解
- Qt之GUI学习笔记(四)——创建对话框
- px与dp与sp之间的转换
- vue组件最佳实践
- JNI交叉编译_NDK插件
- androidStudio升级到2.3之后新建Activity布局变成了约束(ConstraintLayout)布局
- 读取网络时间
- linux 设置环境变量的方法
- 【LeetCode】500. Keyboard Row