shichaohui / PageRecyelerViewDemo

横向分页的RecyclerView,带有页码指示器。
http://blog.csdn.net/u014165119/article/details/46834265
284 stars 68 forks source link

java.lang.IndexOutOfBoundsException: Invalid item position 0(0). Item count:0 #4

Open smallheart opened 6 years ago

syusikoku commented 5 years ago

@Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { if (measuredHeight <= 0 && state.getItemCount() > 0) { // View view = recycler.getViewForPosition(0); View view = recycler.getViewForPosition(0); if (view != null) { measureChild(view, widthSpec, heightSpec); measuredWidth = View.MeasureSpec.getSize(widthSpec); measuredHeight = view.getMeasuredHeight() * getSpanCount(); } } setMeasuredDimension(measuredWidth, measuredHeight); }