Open sunflower-zyb opened 9 years ago
for (int i = 0; i < childCount; i++) {
View child = recycler.getViewForPosition(i);
这里我的childCount = 7 但getViewForPosition(0)出现:
java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4604)
java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0 getViewForPosition 数组越界,
java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0 getViewForPosition 数组越界,
@AllenVork
mLayoutManager.setAutoMeasureEnabled(false)
recyclerView.setHasFixedSize(false)
你这个页面的布局,能给我一份吗!
RecyclerView使用GridLayoutManager,高度设置为wrap_content时无效
标签(空格分隔): RecyclerView GridLayoutManager wrap_content
今天在使用RecyclerView,将布局设置为GridLayoutManager时,发现高度设置为wrap_content无效: Google一下后,结果如下。
于是自定义MyGridLayoutManager,继承自GridLayoutManager,重写onMeasure方法:
此时,RecyclerView便可显示实际高度: 完整代码如下:
第二个构造函数参数reverseLayout的含义是什么呢?官方文档是这么说明的:
实践是检验真理的唯一标准,当设置为true后,效果如下: 可以看到“心情”下面的排列顺序由0~15的递增顺序变为递减了,所以当reverseLayout设置为true时,会将Adapter对应的内容倒着显示
本文中的表格来自Android-RecylerView初识