use of androidx.recyclerview.widget.GridLayoutManager in project simple-stack by Zhuinden.
the class KittenGridFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = view.findViewById(R.id.recyclerview);
recyclerView.setAdapter(new KittenGridAdapter(6));
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
}
use of androidx.recyclerview.widget.GridLayoutManager in project CloudReader by youlookwhat.
the class NavigationContentAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager instanceof GridLayoutManager) {
final GridLayoutManager gridManager = ((GridLayoutManager) manager);
gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int type = getItemViewType(position);
/**
* 根据GridLayoutManager的getSpanSize方法可以动态的设置item跨列数
* 需要设置:4个参数的GridLayoutManager
* new GridLayoutManager(getActivity(),6,GridLayoutManager.VERTICAL,false);
* 这里的6(自己设置的最好设置成偶数)就相当于分母,6默认显示一整行(1列),下面的3 和2 就相当于分子,返回3就是(1/2)所以此类型对应的是2列,返回2就是(1/3)所以此类型对应的是3列
*/
switch(type) {
case StickyHeaderHandler.TYPE_STICKY_VIEW:
// title栏显示一列
return gridManager.getSpanCount();
case TYPE_CONTENT:
// 内容栏显示2列
return 3;
default:
// 默认显示2列
return 3;
}
}
});
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project Transitions-Everywhere by andkulikov.
the class ExplodeAndEpicenterExample method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRecyclerView = new RecyclerView(container.getContext());
mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mRecyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 4));
mRecyclerView.setAdapter(new Adapter());
return mRecyclerView;
}
use of androidx.recyclerview.widget.GridLayoutManager in project UltimateRecyclerView by cymcsg.
the class UltimateRecyclerView method scroll_load_more_detection.
private void scroll_load_more_detection(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManagerType == null) {
if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
} else if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
mTotalItemCount = layoutManager.getItemCount();
mVisibleItemCount = layoutManager.getChildCount();
switch(layoutManagerType) {
case LINEAR:
mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
break;
case GRID:
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager ly = (GridLayoutManager) layoutManager;
lastVisibleItemPosition = ly.findLastVisibleItemPosition();
mFirstVisibleItem = ly.findFirstVisibleItemPosition();
}
break;
case STAGGERED_GRID:
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;
if (mlastPositionsStaggeredGridLayout == null)
mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];
sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);
sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
}
break;
}
if (automaticLoadMoreEnabled) {
if (mTotalItemCount > previousTotal) {
automaticLoadMoreEnabled = false;
previousTotal = mTotalItemCount;
}
}
boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;
if (bottomEdgeHit) {
if (mIsLoadMoreWidgetEnabled) {
/**
*auto activate load more*
*/
if (!automaticLoadMoreEnabled) {
onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
automaticLoadMoreEnabled = true;
}
}
mAdapter.internalExecuteLoadingView();
previousTotal = mTotalItemCount;
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project UltimateRecyclerView by cymcsg.
the class catelogGrid method renderviewlayout.
protected void renderviewlayout(View view) throws Exception {
listview_layout = (UltimateRecyclerView) view.findViewById(getUltimate_recycler_viewResId());
listview_layout.setHasFixedSize(true);
listview_layout.setSaveEnabled(true);
if (mLayoutManager == null) {
mLayoutManager = new GridLayoutManager(view.getContext(), getColumn(), LinearLayoutManager.VERTICAL, false);
}
listview_layout.setLayoutManager(mLayoutManager);
getProgressbar(view);
listview_layout.setAdapter(madapter = getAdatperWithdata());
setUltimateRecyclerViewExtra(listview_layout, madapter);
}
Aggregations