您的位置:首页 > 其它

商城模式转换,recyclerView的LinearLayoutManager转成GridLayoutManager出现的bug

2017-10-19 20:31 218 查看
最近在学习菜鸟商城这个项目,有一节是一个商品列表的转换,默认是用的recyclerView加载LinearLayoutManager的,下面这个样子



我想把recyclerView的layoutManager设置成GridLayoutManager,下图的样子!



这是进入页面时加载的recyclerView

```
mWaresAdapter = new HWAdapter(this, datas);

            mRecyclerview_wares.setAdapter(mWaresAdapter);

            mRecyclerview_wares.setLayoutManager(new LinearLayoutManager(this));

            mRecyclerview_wares.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));

            mRecyclerview_wares.setItemAnimator(new DefaultItemAnimator());

            ```


当点击右上角的按钮的时候,来切换列表的样式,代码是这个样子。



然后就出现了下面的样子。



后来发现,自己转换样式的时候没有setAdapter()



改完以后就正常了,果然在重新设置完layoutManager的时候要重新设置adapter,找的好心塞呀这错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: