LinearLayoutManager linearLayoutManager=new LinearLayoutManager( this); // linearLayoutManager . setOrientation(RecyclerView. HORIZONTAL); oneRecyclerView. setLayoutManager(linearLayoutManager); // 通过setAdapter()的方法将适配器HomeAdapter的对象设置到RecycleView控件上。 oneAdapter=new HomeAdapter(); oneRecyclerView. setAdapter (oneAdapter); LinearLayoutManager linearLayoutManager=new LinearLayoutManager( this); //显示线性垂直 // linearLayoutManager . setOrientation(RecyclerView.HORIZONTAL); twoRecyclerView. setLayoutManager(linearLayoutManager); // 通过setAdapter()的方法将适配器HomeAdapter的对象设置到RecycleView控件上。 twoAdapter=new HomeAdapter(); twoRecyclerView. setAdapter (twoAdapter);
时间: 2024-03-20 14:42:35 浏览: 52
RecyclerView(一).rar
这段代码存在一个问题,即在创建第二个LinearLayoutManager对象时,变量名和类型重复了,需要修改为不同的变量名。可以将第二个LinearLayoutManager对象改为如下:
```
LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
linearLayoutManager2.setOrientation(RecyclerView.HORIZONTAL);
twoRecyclerView.setLayoutManager(linearLayoutManager2);
twoAdapter = new HomeAdapter();
twoRecyclerView.setAdapter(twoAdapter);
```
这样就可以正常设置第二个RecyclerView控件的布局方式和适配器了。
阅读全文