I made RecyclerView with StaggeredGridLayoutManager like this:

I need to add some TextView (one colum like in LinearLayoutManager) in above it. It's like LinearLayoutManager in above and StaggeredGridLayoutManager in bottom. Something like this:

How can i achieve that? Really confused in here, please help.
UPDATE 29-OCT-2015:
I solve it in conjunction with the answer by denis_lor and mato in here: Span multiple columns with RecyclerView
The key is in your adapter, you basically rely on the viewType and then decide what kind of viewholder and layout to inflate. Here an example:
private static final int TYPE_FIRST_ITEM = 0;
private static final int TYPE_ITEM = 1;
...
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_FIRST_ITEM) {
// inflate your view holder for the first item
} else {
// here inflate your view holder for all the other items
}
...
@Override
public int getItemViewType(int position) {
if (position == 0) {
return TYPE_FIRST_ITEM;
} else {
return TYPE_ITEM;
}
}
So basically you have 1 adapter, 2 (or more) viewHolder and thats all. If your adapter should have 2 kind of layout you use 2 viewHolder and layouts, otherwise you use more if you need also a footer layout.
What do you want to happen when scrolling?
If the top view should remain visible, you can wrap the RecyclerView with a LinearLayout with 2 children: TextView and RecyclerView.
If you want it to scroll out, you can use LayoutManager.setSpanSizeLookup, something like this:
layoutManager.setSpanSizeLookup(new SpanSizeLookup() {
@Override
public int getSpanIndex(int position, int spanCount) {
return position % spanCount;
}
@Override
public int getSpanSize(int position) {
if (position != 0) {
return layoutManager.getSpanCount();
}
return 1;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With