RecyclerView条目不能填充的问题
来源:互联网 发布:陕西网络创新研究院 编辑:程序博客网 时间:2024/05/17 04:55
RecyclerView的Item条目不能填充的问题
问题描述:
发现问题是是用这种方式去填充布局不能填充recyclerview,这个时候Item的根布局是LinearLayout:
View childView = mLayoutInflater.inflate(R.layout.item_member_integral_explain, null,false);
方案1.
这个时候保持填充的代码不变化,去修改根布局为RelativeLayout发现可以填充。
方案2.
View childView = mLayoutInflater.inflate(R.layout.item_member_integral_explain, parent,false);//修改填充代码为parent
这样也是可以填充满的,网上多数说的都是该方案。
源码部分:
// Temp is the root view that was found in the xml final View temp = createViewFromTag(root, name, inflaterContext, attrs);//这里是拿到Item的rootview。 ViewGroup.LayoutParams params = null; //这里是需要看我们是否传入了root,如果没有传入的话下面都不会走了,直接返回了这个item的根view了 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);//获取根view的参数 if (!attachToRoot) {//在设置参数进去 // Set the layout params for temp if we are not // attaching. (If we are, we use addView, below) temp.setLayoutParams(params); } } if (DEBUG) { System.out.println("-----> start inflating children"); } // Inflate all children under temp against its context. rInflateChildren(parser, temp, attrs, true); if (DEBUG) { System.out.println("-----> done inflating children"); } // We are supposed to attach all the views we found (int temp) // to root. Do that now. //将我们的item加入到root上。 if (root != null && attachToRoot) { root.addView(temp, params); } // Decide whether to return the root that was passed in or the // top view found in xml. //直接把我们的Item的view返回了。 if (root == null || !attachToRoot) { result = temp; } return result;
上面是填充Item的部分,如果我们传入的inflate方法第二个参数是null的话其实是没有给temp设置参数的,而是直接把temp赋值给了result并返回。
推测结论:
方案1能解决该问题,应该是LinearLayout和RelativeLayout两个view的不同特性导致,这里需要去了解两个view的区别了。
方案2解决问题,是因为对item的根view进行了设置,所以跟view的参数是已经生效了,所以在加入到root上的时候就保持了我们自己设置的属性。
结束语
希望了解这块的同学能提供一些完成的解答。
阅读全文
0 0
- RecyclerView条目不能填充的问题
- RecyclerView的notifyItemRemoved()方法删除条目问题
- 简单解决RecyclerView嵌套的RecyclerView条目显示不全和宽度不能铺满
- 简单解决RecyclerView嵌套的RecyclerView条目显示不全和宽度不能铺满
- Android解决RecyclerView嵌套的RecyclerView或CardView条目显示不全和宽度不能铺满
- RecyclerView的条目监听事件
- recyclerview的点击条目删除
- Recyclerview的条目点击事件
- 点击RecyclerView的条目跳转
- RecyclerView的多条目展示
- ListView项不能完全填充的问题
- RecyclerView/ScrollView中条目弹出PopupMenu导致RecyclerView自动滚动的问题
- listView条目不能点击问题
- 【RecyclerView】 item不能横向充满的问题
- RecyclerView的条目拖拽和条目滑动
- Recyclerview嵌套Recyclerview,条目显示不全和宽度不能铺满不能同时满足
- RecyclerView+OKhttp+item的条目加载
- RecyclerView的多条目加载适配器
- vtk 一个actor多条线段
- TMMi认证的评估方法有多少种?
- IOS上传图片翻转处理重力并压缩大小
- 文件上传前端模板
- 使用scrapy-redis实现分布式爬虫
- RecyclerView条目不能填充的问题
- SQL中的CASE WHEN语句
- linux 部署javaweb环境
- burnside引理与Polya定理计数法
- sql算法总结
- MarkDown基本使用
- HashMap源码剖析
- 防雪崩利器Hystrix
- 浅谈链式编程