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

GridLayoutManager usage #7

Open
IamEgor opened this issue Feb 24, 2016 · 3 comments
Open

GridLayoutManager usage #7

IamEgor opened this issue Feb 24, 2016 · 3 comments
Labels

Comments

@IamEgor
Copy link

IamEgor commented Feb 24, 2016

Greetings!

I'm trying to use this lib with GridLayoutManager.
But when I've done this, the result was not as I expected.

device-2016-02-25-015937
device-2016-02-25-020010
device-2016-02-25-020050

When all tabs are expanded thats fine. In other cases it's looked wired.
I use this code in my Activity.

final GridLayoutManager manager = new GridLayoutManager(this, 2);
        recycler.setLayoutManager(manager);

        final PeopleAdapter adapter = new PeopleAdapter(this);
        recycler.setAdapter(adapter);

        manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return adapter.isHeader(position) ? manager.getSpanCount() : 1;
            }
        });
@grennis
Copy link
Owner

grennis commented Feb 25, 2016

Interesting, what does your implementation of isHeader look like?

@IamEgor
Copy link
Author

IamEgor commented Feb 25, 2016

I just save list.

private List<PeopleListItem> items;

    private List<PeopleListItem> items;

    public PeopleAdapter(Context context) {
        super(context);

        items = getSampleItems();
        setItems(items);
    }

Add method to PeopleAdapter.

public boolean isHeader(int location) {
        return items.get(location).isHeader();
    }

Save into variable type(Header or not) and add method to PeopleListItem.

public static class PeopleListItem extends ExpandableRecyclerAdapter.ListItem {

        public String Text;
        private int type;

        public PeopleListItem(String group) {
            super(TYPE_HEADER);

            type = TYPE_HEADER;
            Text = group;
        }

        public PeopleListItem(String first, String last) {
            super(TYPE_PERSON);

            type = TYPE_PERSON;
            Text = first + " " + last;
        }

        public boolean isHeader() {
            return type == TYPE_HEADER;
        }

    }

@grennis
Copy link
Owner

grennis commented Feb 25, 2016

It must have something to do with the fact that as the groups are expanded/collapsed, the positions of the headers change. The grid layout doesn't realize that the column spans are changing at those positions. I will need to look into it. I've never tried to use it with grid layout manager.

@grennis grennis added the bug label Mar 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants