jmartinesp / SpannedGridLayoutManager

Android RecyclerView.LayoutManager that resizes and reorders views based on SpanSize
MIT License
600 stars 105 forks source link

firstVisiblePosition 获取到的总是1 #41

Open ghost opened 5 years ago

ghost commented 5 years ago

在滚动后再回滚到列表开始位置,然后调用firstVisiblePosition 获取到的总是1而不是0

ghost commented 5 years ago

SpannedGridLayoutManager layoutManager = new SpannedGridLayoutManager(SpannedGridLayoutManager.Orientation.HORIZONTAL, 4); layoutManager.setItemOrderIsStable(true); layoutManager.setSpanSizeLookup(new SpannedGridLayoutManager.SpanSizeLookup(new Function1<Integer, SpanSize>(){ @Override public SpanSize invoke(Integer position) { final int span1 = (position == 0 || position == 6 || position == 13 || position == 5 ? 2 : 1); final int span2 = (position == 0 || position == 6 || position == 13 ? 2 : position == 5 ? 4 : 1); return new SpanSize(span1, span2); } })); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.addItemDecoration(new SpaceItemDecorator(5, 5, 5, 5));

    mAdapter = new SpannedAdapter(getContext(), mRecyclerView);
    mAdapter.setDatas(ItemDatas.getDatas(60));
    mRecyclerView.setAdapter(mAdapter);