Android 6.0 解决Recyclerview 在 Scrollview 中不能高度自适应问题
在项目中遇到解决Recyclerview 在 Scrollview 中不能高度自适应问题:android6.0以下机器是可以的,但是6.0就不能自适应,经网上查询应该是一个bug。
在网上查询资料终于找到解决方法
其他网站重写LayoutManager的方法试了都不行。
最终解决办法很简单,如下: 在 recyclerview 外面再嵌套一层 RelativeLayout即可。代码 如下:
xml- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
activity:
private void initWidget() { selImageList = new ArrayList<>(); adapter = new ImagePickerAdapter(this, selImageList, maxImgCount); adapter.setOnItemClickListener(this); mRecyclerViewImage.setLayoutManager(new GridLayoutManager(this, 4)); mRecyclerViewImage.setHasFixedSize(true); mRecyclerViewImage.setAdapter(adapter); }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
以上方法亲测可用。