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

visibilityProvider is not working fine with GridLayoutMananger #131

Closed
aolaca opened this issue Sep 22, 2020 · 3 comments
Closed

visibilityProvider is not working fine with GridLayoutMananger #131

aolaca opened this issue Sep 22, 2020 · 3 comments
Labels
bug Something isn't working expected behavior The library is behaving correctly

Comments

@aolaca
Copy link

aolaca commented Sep 22, 2020

Description

With multiple columns,the cell in middle column is bigger than the sidles.

RecyclerViewDivider version:
version:3.3.0
API level:

androidx:1.1.0
ANDROID_BUILD_MIN_SDK_VERSION   : 23,
ANDROID_BUILD_TARGET_SDK_VERSION: 29,
ANDROID_COMPILE_SDK_VERSION     : 29,

How to reproduce it:

  • Use GridLayoutManager with VERTICAL

  • spanCount is 3

  • add the divider as the follwing sample code

as the uppper steps ,it will reporduce.
remove visibilityProvider method,it works fine.

Sample code:

recycler.addItemDecoration(new DividerBuilder(getContext())
                .colorRes(R.color.transparent)
                .visibilityProvider(new VisibilityProvider() {
                    @Override
                    public boolean isDividerVisible(@NotNull Grid grid, @NotNull Divider divider) {
                        return true;
                    }
                })
                .sizeProvider(new SizeProvider() {
                    int dp16 = Tool.dimens().dp2px(16);
                    @Override
                    public int getDividerSize(@NotNull Grid grid, @NotNull Divider
                            divider, @NotNull Drawable drawable) {
                        return dp16;
                    }
                }) . build());

Stack trace:

Paste the stack trace here.
@aolaca aolaca added the bug Something isn't working label Sep 22, 2020
@fondesa
Copy link
Owner

fondesa commented Sep 22, 2020

It's the wanted behavior, I'm quoting the documentation of DividerBuilder.visibilityProvider:

IMPORTANT: The default [DividerOffsetProvider] can't ensure the same size of the items in a grid when this method is called.
If you want a different behavior, you can specify a custom [DividerOffsetProvider] with [offsetProvider].

The auto sizing of the cells with a GridLayoutManager is not supported with VisibilityProvider and SizeProvider, you have two choices:

  • use the non-provider API e.g. size(), showFirstDivider(), etc..
  • use the provider API and add a DividerOffsetProvider handling the sizing by yourself

BTW your implementation above can be made in this way and the cells will be autosized:

recycler.addItemDecoration(new DividerBuilder(getContext())
    .colorRes(R.color.transparent)
    .showFirstDivider()
    .showLastDivider()
    .showSideDividers()
    .size(16, TypedValue.COMPLEX_UNIT_DIP)
    .build())

@aolaca
Copy link
Author

aolaca commented Sep 23, 2020

@fondesa
Thanks your comment.

In my project , the complex divide is required,so I have to use the size and visiblity provider.
I will try to use DividerOffsetProvider to handle the sizing of each cell.

BYW,The divider library, it is very helpful,thank you a lot.

@fondesa fondesa added the expected behavior The library is behaving correctly label Sep 23, 2020
@fondesa
Copy link
Owner

fondesa commented Sep 23, 2020

You are welcome.
If you need further information, feel free to reopen the issue.

@fondesa fondesa closed this as completed Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working expected behavior The library is behaving correctly
Projects
None yet
Development

No branches or pull requests

2 participants