Reputation: 1870
I was wondering how to show the snapshot of my notes, checklists, images in the grid view. I have no trouble creating the grid view but creating a preview of it is the challenge I'm facing right now as I need to add different type of views(text, checklist, imageview) to the grid according to their time of creation. Works fine for a single type of view like image or text only.
Or in other words. How do I add the different views dynamically to the GridView Adapter?
All or any help is appreciated.
Thanks.
Upvotes: 16
Views: 9406
Reputation: 9
recyclerView= (RecyclerView) findViewById(R.id.recycler);
recyclerView.setLayoutManager(new
StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
initData();
MasonryAdapter adapter=new MasonryAdapter(productList);
recyclerView.setAdapter(adapter);
SpacesItemDecoration decoration=new SpacesItemDecoration(16);
recyclerView.addItemDecoration(decoration);
Upvotes: 1
Reputation: 170
Take a look at this recycle view with stagged
This manage make all what you need StaggeredGridLayoutManager or look at this sorce Heterogenous Layouts inside RecyclerView
Upvotes: 1
Reputation: 7138
More than likely Google is using something similar to GridLayout, if not actually using a GridLayout.
Chances are the layout is also created programmatically to allow for the widgets to be different sizes based on the content that they each display.
Upvotes: 1
Reputation: 2402
They surely do not use a GridView for google Keep - but probably an Adapter nonetheless.
To use different Views with your Adapter you can use different View types:
getViewTypeCount()
to return the number of View types you support.getItemViewType(int position)
for this specific item.getView(int position, View convertView, ViewGroup parent)
.Keep in mind that the rules for recycling, ViewHolder and so on still apply. For multiple types recycling only happens for the correct type.
Marcus Körner shared a gist by Jake Wharton on G+ recently that might be useful.
Upvotes: 3