yqritc/RecyclerView-FlexibleDivider

it seems VerticalDividerItemDecoration has some issue

jacky1234 opened this issue · 1 comments

VerticalDividerItemDecoration does not work collectly.

here is my codes:

recyclerView.addItemDecoration(new VerticalDividerItemDecoration.Builder(this)
                .margin(50, 50)
                .color(Color.BLUE)
                .size(30)
                .build());
        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)
                .margin(50, 50)
                .color(Color.YELLOW)
                .size(30)
                .build());

but the result seems incorrect!
short of vertical color draw,as the following:
default

hey if you have fix 3 vertical line than you can do like

In VerticalDividerItemDecoration.class

@OverRide
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
Rect bounds = new Rect(0, 0, 0, 0);
int transitionX = (int) ViewCompat.getTranslationX(child);
int transitionY = (int) ViewCompat.getTranslationY(child);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
bounds.top = parent.getPaddingTop() +
mMarginProvider.dividerTopMargin(position, parent) + transitionY;
bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (isReverseLayout) {
            bounds.right = child.getLeft() - params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.rightMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX;
        } else {
            bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;

            if (position % 2 == 0) {
                bounds.left = 2 * (child.getRight() + params.rightMargin + halfSize + transitionX);
            }
            else {
                bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
            }

        }
        bounds.right = bounds.left;
    }

its work well