商城模式转换,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,找的好心塞呀这错误。
我想把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,找的好心塞呀这错误。
相关文章推荐
- RecyclerView自带bug,切换数据出现IndexOutOfBoundsException
- Support v-7 recycler view 出现IndexOutOfBoundsException: Inconsistency detected.异常解决办法。
- 学习RecyclerView时出现的错误
- RecyclerView嵌套使用RadioGroup出现的问题
- 用RecyclerView+CardView实现 商城首页
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 关于MVP设计模式 和 BaseRecyclerViewAdapterHelperV2.4.4 Android
- RecyclerView的Item复用出现问题导致排版混乱
- 出现Error inflating class android.support.v7.widget.RecyclerView错误的解决办法
- 关于导入com.android.support:recyclerview出现的问题
- 装饰设计模式 - RecyclerView添加头部和底部
- glmis项目工作日志4_解决RecyclerView中使用CheckBox时出现数据错乱的问题。
- RecyclerView 复用出现 CheckBox 或者 设置背景混乱问题
- 使用RecyclerView时出现异常IllegalArgumentException的原因
- [置顶] Android 6.0 设备上RecyclerView只显示一行的Bug修复
- ScrollView嵌套RecyclerView,RecyclerView总是把它上面的控件顶出页面(页面出现自己滚动)
- 使用RecyclerView实现QQ空间广告位一个位置两个图时偶遇bug
- 安卓——RecyclerView的GridView模式如何合并grid格
- ViewPager里面ImageView图片切换出现bug
- 解决ScrollView嵌套RecyclerView时滑动出现的卡顿