Android关于RecycleView不走onBindViewHolder和onCreateViewHolder问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/codekxx/article/details/82664445

在添加适配器的时候,忘记设置条目样式!

添加以下代码既能解决!

RecyclerView.LayoutManager layout=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);//(垂直布局、水平布局)
参数1:上下文
参数2:水平还是垂直
参数3:为false表示数据按输入的顺序显示,为true表示数据逆向显示。

StaggeredGridLayoutManager layout=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);//(瀑布流布局)
参数1:为每行几个元素
参数2:为垂直瀑布还是水平瀑布




recyclerView.setLayoutManager(layout);

猜你喜欢

转载自blog.csdn.net/codekxx/article/details/82664445