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

RecyclerView with different size rows #56

Closed
Marcelhozeman opened this issue Jun 28, 2016 · 9 comments
Closed

RecyclerView with different size rows #56

Marcelhozeman opened this issue Jun 28, 2016 · 9 comments

Comments

@Marcelhozeman
Copy link

Hello,

I've got a RecyclerView with multiple ViewHolders that all have a separate layout file with a different height (for example 20dp, 40dp and 60dp). So each row has a different (but static) height. When i use the TouchScrollBar it doesn't scroll smoothly trough the items. Is there a way to support this?

@turing-tech
Copy link
Owner

Have your adapter extend ICustomScrolling and invoke the useCustomScolling() method on your bar setup.

@Marcelhozeman
Copy link
Author

Marcelhozeman commented Jun 29, 2016

Thanks! I forgot to set useCustomScrolling. Didn't see that method in the header tutorial. I've implemented this 2 interfaces now: FastScrollerUtil.IHeaderAdapter, ICustomScroller. And i am returning the height of my biggest ViewHolder in the getRowHeight method (IHeaderAdapter interface method). Is this the correct way to do this?

@MFlisar
Copy link
Contributor

MFlisar commented Jun 30, 2016

This won't work correctly. The logic behind the HeaderAdapter is 1 header and 1 item, whereas every header has the same height and every item has the same height...

@turing-tech
Copy link
Owner

Exactly. You'll need to remove that interface (keep ICustomScrolling) and fill in the methods yourself.

@Marcelhozeman
Copy link
Author

Thanks guys,

It works now.

@MinaHany
Copy link

Just wanted to say thanks very much for this great library! The only library I could find where I could have different row heights with scrolling working as expected.

@joaquincorrales
Copy link

joaquincorrales commented Mar 22, 2017

@MinaHany @Marcelhozeman Hey, can you show some adapter code as far as implementing the IHeaderAdapter and ICustomScroller? We followed the Header tutorial to the tee but have issues with scrolling. It only seems to get one letter and doesn't work anywhere near expected. We're sure we did something wrong but have spent hours and are unable to figure it out. Appreciate it!

@turing-tech
Copy link
Owner

If you could provide a sample of your code that would be the easiest. If not I can write up an example tomorrow.

@MinaHany
Copy link

MinaHany commented Mar 24, 2017

@joaquincorrales I am not implementing IHeaderAdapter, just ICustomScroller so not sure if my example will help but here it is anyway:

private List<Integer> sectionHeights;

@Override
public int getDepthForItem(int index) {
    return getDepth(index);
}

@Override
public int getItemIndexForScroll(float progress) {
    float depth = 0;
    float totalDepth = getTotalDepth();
    for (int i = 0; i < sectionHeights.size(); i++) {
        depth += sectionHeights.get(i);
        if (progress <= depth / totalDepth) {
            return i;
        }
    }
    return sectionHeights.size() - 1;
}

@Override
public int getTotalDepth() {
    return getDepth(sectionHeights.size());
}

private int getDepth(int endIndex) {
    int depth = 0;
    for (int i = 0; i < endIndex; i++) {
        depth += sectionHeights.get(i);
    }
    return depth;
}

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

5 participants