use of android.support.v7.widget.RecyclerView.LayoutManager 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.RecyclerView.LayoutManager in project glide by bumptech.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view);
Glide.with(this).load(R.raw.large_giphy_logo).into(giphyLogoView);
RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
gifList.setLayoutManager(layoutManager);
RequestBuilder<Drawable> gifItemRequest = Glide.with(this).asDrawable();
ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>();
adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider);
gifList.setAdapter(adapter);
RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, 4);
gifList.addOnScrollListener(preloader);
}
use of android.support.v7.widget.RecyclerView.LayoutManager 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.RecyclerView.LayoutManager in project FlexibleAdapter by davideas.
the class FragmentStaggeredLayout method initializeRecyclerView.
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
// Initialize Adapter and RecyclerView
// ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity());
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
// Customize the speed of the smooth scroll.
// NOTE: Every time you change this value you MUST recreate the LayoutManager instance
// and to assign it again to the RecyclerView!
TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f;
mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
// This value is restored to 100f (default) right here, because it is used in the
// constructor by Android. If we don't change it now, others LayoutManager will be
// impacted too by the above modification!
TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 100f;
mRecyclerView.setAdapter(mAdapter);
//Size of RV will not change
mRecyclerView.setHasFixedSize(true);
// NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
// a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
// Experimenting NEW features (v5.0.0)
//Show Headers at startUp!
mAdapter.setDisplayHeadersAtStartUp(true).setNotifyMoveOfFilteredItems(true).setPermanentDelete(//Default=true
true).setOnlyEntryAnimation(true);
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
// Add 1 Scrollable Header
mAdapter.addScrollableHeader(new ScrollableUseCaseItem(getString(R.string.staggered_use_case_title), getString(R.string.staggered_use_case_description)));
}
use of android.support.v7.widget.RecyclerView.LayoutManager in project FlexibleAdapter by davideas.
the class ExampleAdapter method showLayoutInfo.
/*
* HEADER VIEW
* This method shows how to add Header View as it was for ListView.
* Same Header item is enqueued for removal with a delay.
* The view is represented by a custom Item type to better represent any dynamic content.
*/
public void showLayoutInfo(boolean scrollToPosition) {
if (!hasSearchText()) {
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(Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
// NOTE: If you have to change at runtime the LayoutManager AND add
// Scrollable Headers, consider to add them in post, using a delay >= 0
// otherwise scroll animations on all items will not start correctly.
addScrollableHeaderWithDelay(item, 1200L, scrollToPosition);
removeScrollableHeaderWithDelay(item, 4000L);
}
}
Aggregations