项目中遇到多个recyclerview嵌套时,要么只能显示一个Item,要么Item宽度不能铺满填充父布局
总结一下:
子recyclerview(最里面的)onCreateViewHolder方法中应这样写inflate(R.layout.item_fragment_study_hot_item, parent, false);
然后其父布局inflate(R.layout.item_fragment_study_hot_body, null, false);
这样的写法,解决了recyclerview只能显示一个Item,还有问题是宽度不能铺满,然后在写父recyclerview的setLayoutManager方法时,这样写:
//RecyclerView 条目布局宽度设置match_parent无效果的问题解决
//这里为了解决recycleview不能撑满全屏的问题,这里layoutManager不管你布局里是否设置,都不准确,所以需要在代码里
//重新设置MATCH_PARENT
LinearLayoutManager layoutManager = new LinearLayoutManager(context) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
};
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
继续阅读与本文标签相同的文章
自动驾驶攻破的难点在哪,何时能到Level 5?
linux中select函数用法
-
增值税发票管理系统2.0版即将上线啦
2026-05-18栏目: 教程
-
楼上请让路 RoarCTF2019 writeup
2026-05-18栏目: 教程
-
恒泰聚能节电分享:人工智能开始发挥其节能潜力
2026-05-18栏目: 教程
-
CMU 15-721 16-服务器端的逻辑执行 Server -side Logic Execution
2026-05-18栏目: 教程
-
谷歌搜索广告出价方式
2026-05-18栏目: 教程
