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

Example of how to implement a staggered layout with sticky headers #521

Closed
jrcacd opened this issue Jan 19, 2018 · 7 comments
Closed

Example of how to implement a staggered layout with sticky headers #521

jrcacd opened this issue Jan 19, 2018 · 7 comments

Comments

@jrcacd
Copy link
Contributor

jrcacd commented Jan 19, 2018

Is there an example of how to implement a staggered layout with sticky headers as showed in your screenshot?

@davideas
Copy link
Owner

@jrcacd, the difference from grid and linear is of course the LayoutManager and the full span support for the item identified as header.

// In the ViewHolder constructor
setFullSpan(true);

Which perform this code in FlexibleViewHolder:

/**
 * Support for StaggeredGridLayoutManager.
 *
 * @param enabled true to enable full span size, false to disable
 */
public void setFullSpan(boolean enabled) {
    if (itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        ((StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams())
            .setFullSpan(enabled);
    }
}

@jrcacd
Copy link
Contributor Author

jrcacd commented Jan 22, 2018

My header must inherit from which one: FlexibleViewHolder, AbstractHeaderItem, AbstractSectionableItem?

@davideas
Copy link
Owner

davideas commented Jan 22, 2018

The item form AbstractHeaderItem, and the Holder from FlexibleViewHolder paying attention at the constructor parameters (see docs).

@jrcacd
Copy link
Contributor Author

jrcacd commented Jan 22, 2018

Apparently I've make. But I seem to have found a mistake.

When I scroll and the last item before the next heading is in the left column, it works fine, meaning the next heading touch on the previous one and pushes it up.

When I scroll and the last item before the next heading is in the right column (I only have 2 columns) the next heading disappears from where it is and jumps to the top (to the place where the previous heading was)

@jrcacd jrcacd closed this as completed Jan 22, 2018
@jrcacd jrcacd reopened this Jan 22, 2018
@jrcacd jrcacd closed this as completed Jan 22, 2018
@jrcacd jrcacd reopened this Jan 22, 2018
@davideas
Copy link
Owner

@jrcacd, yes I see it also in the demoApp.
I will have to investigate what is the cause, probably the findFirstVisibleItemPositions(null)[0] is not good.
Is that array referring to the column span?

@jrcacd
Copy link
Contributor Author

jrcacd commented Jan 22, 2018

Yes

@jrcacd
Copy link
Contributor Author

jrcacd commented Feb 4, 2018

Great!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants