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

it seems VerticalDividerItemDecoration has some issue #46

Open
jacky1234 opened this issue Oct 3, 2016 · 1 comment
Open

it seems VerticalDividerItemDecoration has some issue #46

jacky1234 opened this issue Oct 3, 2016 · 1 comment

Comments

@jacky1234
Copy link

jacky1234 commented Oct 3, 2016

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

@jacky1234 jacky1234 changed the title it seems HorizontalDividerItemDecoration has some issue it seems VerticalDividerItemDecoration has some issue Oct 3, 2016
@Madhuri98
Copy link

Madhuri98 commented Mar 17, 2017

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

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

2 participants