use of android.support.v7.widget.GridLayoutManager in project MultiType by drakeet.
the class MultiSelectActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multi_select);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return (items.get(position) instanceof Category) ? SPAN_COUNT : 1;
}
});
selectedSet = new TreeSet<>();
recyclerView.setLayoutManager(layoutManager);
adapter = new MultiTypeAdapter();
adapter.applyGlobalMultiTypePool();
adapter.register(Square.class, new SquareViewBinder(selectedSet));
loadData();
assertAllRegistered(adapter, items);
recyclerView.setAdapter(adapter);
setupFAB();
}
use of android.support.v7.widget.GridLayoutManager in project MultiType by drakeet.
the class BilibiliActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
adapter = new MultiTypeAdapter();
adapter.applyGlobalMultiTypePool();
adapter.register(Post.class, new PostViewBinder());
adapter.register(PostList.class, new HorizontalPostsViewBinder());
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
SpanSizeLookup spanSizeLookup = new SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object item = items.get(position);
return (item instanceof PostList || item instanceof Category) ? SPAN_COUNT : 1;
}
};
layoutManager.setSpanSizeLookup(spanSizeLookup);
recyclerView.setLayoutManager(layoutManager);
int space = getResources().getDimensionPixelSize(R.dimen.normal_space);
recyclerView.addItemDecoration(new PostItemDecoration(space, spanSizeLookup));
recyclerView.setAdapter(adapter);
JsonData data = new JsonData();
items = new ArrayList<>();
for (int i = 0; i < 10; i++) {
/* You also could use Category as your CategoryItemContent directly */
items.add(data.category0);
items.add(data.postArray[0]);
items.add(data.postArray[1]);
items.add(data.postArray[2]);
items.add(data.postArray[3]);
items.add(data.postArray[0]);
items.add(data.postArray[1]);
items.add(new PostList(data.postList));
}
adapter.setItems(items);
adapter.notifyDataSetChanged();
}
use of android.support.v7.widget.GridLayoutManager in project RecyclerRefreshLayout by dinuscxj.
the class HeaderViewRecyclerAdapter method adjustSpanSize.
public void adjustSpanSize(RecyclerView recycler) {
if (recycler.getLayoutManager() instanceof GridLayoutManager) {
final GridLayoutManager layoutManager = (GridLayoutManager) recycler.getLayoutManager();
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
boolean isHeaderOrFooter = isHeaderPosition(position) || isFooterPosition(position);
return isHeaderOrFooter ? layoutManager.getSpanCount() : 1;
}
});
}
if (recycler.getLayoutManager() instanceof StaggeredGridLayoutManager) {
this.mIsStaggeredGrid = true;
}
}
use of android.support.v7.widget.GridLayoutManager in project FlexibleAdapter by davideas.
the class OverallAdapter method showLayoutInfo.
/*
* HEADER/FOOTER VIEW
* This method show how to add Header/Footer View as it was for ListView.
* The secret is the position! 0 for Header; itemCount for Footer ;-)
* The view is represented by a custom Item type to better represent any dynamic content.
*/
public void showLayoutInfo(boolean scrollToPosition) {
if (!hasSearchText()) {
//Define Example View
final ScrollableLayoutItem item = new ScrollableLayoutItem("LAY-L");
if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
item.setId("LAY-S");
item.setTitle(mRecyclerView.getContext().getString(R.string.staggered_layout));
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
item.setId("LAY-G");
item.setTitle(mRecyclerView.getContext().getString(R.string.grid_layout));
} else {
item.setTitle(mRecyclerView.getContext().getString(R.string.linear_layout));
}
item.setSubtitle(mRecyclerView.getContext().getString(R.string.columns, String.valueOf(eu.davidea.flexibleadapter.utils.Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
addScrollableHeaderWithDelay(item, 500L, scrollToPosition);
removeScrollableHeaderWithDelay(item, 3000L);
}
}
use of android.support.v7.widget.GridLayoutManager in project FlexibleAdapter by davideas.
the class FragmentEndlessScrolling method onPrepareOptionsMenu.
@Override
public void onPrepareOptionsMenu(Menu menu) {
Log.v(TAG, "onPrepareOptionsMenu called!");
MenuItem gridMenuItem = menu.findItem(R.id.action_list_type);
if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp);
gridMenuItem.setTitle(R.string.linear_layout);
} else {
gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp);
gridMenuItem.setTitle(R.string.grid_layout);
}
}
Aggregations