Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some suggest and some problem #34

Open
ChoicesWang opened this issue Mar 9, 2016 · 0 comments
Open

some suggest and some problem #34

ChoicesWang opened this issue Mar 9, 2016 · 0 comments

Comments

@ChoicesWang
Copy link

Sorry.My English not good.
我认为应该分成 GridItemDecoration 和 LinearItemDecoration 。在每个item的周围绘制想要的divider。
这样实现起来比较简单。如果是GridLayoutManager,垂直的时候,则应该在最后一列右边 和 最后一行的下面不添加分割线。
下面是我写的一个例子,相信你能看懂

I think it should be divided into GridItemDecoration and LinearItemDecoration.Draw divider around each item instead of entire row / column.
If it's GridLayoutManager, you should not add the dividing line in the last column to the right and below the last line when vertical and vice versa.
I just like to think of it, it's easier for me to think of it, as the work that I do.
Here is an example of what I wrote, I believe you can understand

public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        outRect.left = getDividerSize();
        outRect.bottom = getDividerSize();
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        RecyclerView.Adapter adapter = parent.getAdapter();
        int itemCount = adapter.getItemCount();
        int position = parent.getChildAdapterPosition(view);
        int spanCount = gridLayoutManager.getSpanCount();
        GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
        int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
        int spanGroupIndex = spanSizeLookup.getSpanGroupIndex(position, spanCount);
        int lastSpanGroupIndex = spanSizeLookup.getSpanGroupIndex(itemCount - 1, spanCount);
        if (lastSpanGroupIndex == spanGroupIndex) outRect.bottom = 0;
        if (spanIndex == 0) outRect.left = 0;
        return;
    }
    Log.e(TAG, "RecyclerView must have GridLayoutManager");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant