LayoutManagerGroup
LayoutManagerGroup copied to clipboard
PickerLayoutManager 在recyclerview-v7:27.1.1版本出错
java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0 android.support.v7.widget.RecyclerView{901d672 VFED..... .F....I. 0,0-0,0 #7f0800c6 app:id/recycler1}, adapter:com.dingmouren.example.layoutmanagergroup.fragment.PickerFragment$MyAdapter@34b3ac3, layout:com.dingmouren.layoutmanagergroup.picker.PickerLayoutManager@8c19f40, context:com.dingmouren.example.layoutmanagergroup.MainActivity@21e0b16
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5779)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at com.dingmouren.layoutmanagergroup.picker.PickerLayoutManager.onMeasure(PickerLayoutManager.java:69)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3210)
at android.view.View.measure(View.java:23279)
...
解决办法:加个判断state.getItemCount()>0,不然 recycler.getViewForPosition(0)就会报IndexOutOfBoundsException错误
...
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
if (getItemCount() != 0 && mItemCount != 0&&state.getItemCount()>0) {
View view = recycler.getViewForPosition(0);
...
非常感谢!
rride public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { if (getItemCount() != 0 && mItemCount != 0&&state.getIt
判断之后,你会发现,最底部的无法选中, 测量出了问题
@Override public boolean isAutoMeasureEnabled() { if (this.mItemCount != 0){ return false; } return super.isAutoMeasureEnabled(); }
在LayoutManager按上述代码样式重写即可解决