Java Code Examples for androidx.recyclerview.widget.StaggeredGridLayoutManager#VERTICAL
The following examples show how to use
androidx.recyclerview.widget.StaggeredGridLayoutManager#VERTICAL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DividerGridItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0) { return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { // 如果是最后一列,则不需要绘制右边 if ((pos + 1) % spanCount == 0) { return true; } } else { childCount = childCount - childCount % spanCount; // 如果是最后一列,则不需要绘制右边 if (pos >= childCount) return true; } } return false; }
Example 2
Source File: DividerGridItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一行,则不需要绘制底部 return true; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); // StaggeredGridLayoutManager 且纵向滚动 if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; // 如果是最后一行,则不需要绘制底部 if (pos >= childCount) return true; } else { // 如果是最后一行,则不需要绘制底部 if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example 3
Source File: DividerGridItemDecoration.java From RvHelper with Apache License 2.0 | 6 votes |
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一行,则不需要绘制底部 return true; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); // StaggeredGridLayoutManager 且纵向滚动 if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; // 如果是最后一行,则不需要绘制底部 if (pos >= childCount) return true; } else { // StaggeredGridLayoutManager 且横向滚动 // 如果是最后一行,则不需要绘制底部 if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example 4
Source File: GridDividerItemDecoration.java From BaseProject with Apache License 2.0 | 6 votes |
/** * 判断是否是最后一列 * @param parent * @param pos * @param spanCount * @param childCount * @return */ private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边 return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % spanCount == 0) {// 最后一列 return true; } } else { } } return false; }
Example 5
Source File: NoteListFragment.java From android-notepad with MIT License | 6 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState){ super.onActivityCreated(savedInstanceState); if (folder != null) mToolbar.setTitle(folder.getName()); mToolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); mToolbar.setNavigationOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ ((HomeActivity) getActivity()).mDrawerLayout.openDrawer(Gravity.LEFT); } }); StaggeredGridLayoutManager slm = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); slm.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS); mRecyclerView.setLayoutManager(slm); adapter = new Adapter(zeroNotesView, folder); mRecyclerView.setAdapter(adapter); adapter.loadFromDatabase(); }
Example 6
Source File: DividerGridItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一行,则不需要绘制底部 return true; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); // StaggeredGridLayoutManager 且纵向滚动 if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; // 如果是最后一行,则不需要绘制底部 if (pos >= childCount) return true; } else { // 如果是最后一行,则不需要绘制底部 if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example 7
Source File: GridDividerDecoration.java From pandora with Apache License 2.0 | 6 votes |
private boolean isLastRow(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { int lines = childCount % spanCount == 0 ? childCount / spanCount : childCount / spanCount + 1; return lines == pos / spanCount + 1; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; if (pos >= childCount) return true; } else { if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example 8
Source File: DividerGridItemDecorationUtils.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) { LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一列,则不需要绘制右边 return true; } } return false; }
Example 9
Source File: ListFragment.java From Pixiv-Shaft with MIT License | 5 votes |
protected void staggerRecyclerView() { StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager( 2, StaggeredGridLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(manager); mRecyclerView.addItemDecoration(new SpacesItemDecoration( DensityUtil.dp2px(8.0f))); }
Example 10
Source File: OverviewStaggeredGridFragment.java From Easy_xkcd with Apache License 2.0 | 5 votes |
@Override protected void setupAdapter() { StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); manager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); rv.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); rvAdapter = new GridAdapter(); rv.setAdapter(rvAdapter); super.setupAdapter(); }
Example 11
Source File: StaggeredGridLayoutInfo.java From litho with Apache License 2.0 | 5 votes |
@Override public int computeWrappedHeight(int maxHeight, List<ComponentTreeHolder> componentTreeHolders) { final int itemCount = componentTreeHolders.size(); final int spanCount = mStaggeredGridLayoutManager.getSpanCount(); int measuredHeight = 0; switch (mStaggeredGridLayoutManager.getOrientation()) { case StaggeredGridLayoutManager.VERTICAL: for (int i = 0; i < itemCount; i += spanCount) { measuredHeight += LayoutInfoUtils.getMaxHeightInRow(i, i + spanCount, componentTreeHolders); measuredHeight += LayoutInfoUtils.getTopDecorationHeight(mStaggeredGridLayoutManager, i); measuredHeight += LayoutInfoUtils.getBottomDecorationHeight(mStaggeredGridLayoutManager, i); if (measuredHeight > maxHeight) { measuredHeight = maxHeight; break; } } return measuredHeight; case StaggeredGridLayoutManager.HORIZONTAL: default: throw new IllegalStateException( "This method should only be called when orientation is vertical"); } }
Example 12
Source File: GirlFragment.java From Girls with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_fragment, null); mRecyclerView = rootView.findViewById(R.id.activity_recycke_view); //设置布局管理器,2表示两列,并且是竖直方向的瀑布流 StaggeredGridLayoutManager mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager); //设置adapter mRecyclerView.setAdapter(mGirlAdapter); mRecyclerView.setHasFixedSize(true); //设置Item增加、移除动画 mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mFloatingActionButton = rootView.findViewById(R.id.fab_girl); mFloatingActionButton.attachToRecyclerView(mRecyclerView); mCircularProgressBar = rootView.findViewById(R.id.circular_progressbar); swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setColorSchemeColors( getResources().getColor(R.color.holo_red_light), getResources().getColor(R.color.holo_green_light), getResources().getColor(R.color.holo_blue_bright)); //swipeRefreshLayout 设置下拉刷新事件 swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { getData(); //成功了 关闭刷新 swipeRefreshLayout.setRefreshing(false); } }); return rootView; }
Example 13
Source File: FragmentRecmdIllust.java From Pixiv-Shaft with MIT License | 5 votes |
@Override public void initRecyclerView() { StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); baseBind.recyclerView.setLayoutManager(layoutManager); baseBind.recyclerView.addItemDecoration(new SpacesItemWithHeadDecoration(DensityUtil.dp2px(8.0f))); }
Example 14
Source File: DividerGridItemDecoration.java From cv4j with Apache License 2.0 | 5 votes |
/** * 是否是最后一行 */ private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一行,则不需要绘制底部 return true; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); // StaggeredGridLayoutManager 且纵向滚动 if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; // 如果是最后一行,则不需要绘制底部 if (pos >= childCount) return true; } else // StaggeredGridLayoutManager 且横向滚动 { // 如果是最后一行,则不需要绘制底部 if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example 15
Source File: RecyclerViewHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 4 votes |
public static StaggeredGridLayoutManager getDefaultStaggeredGridLayoutManager(int column) { StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( column, StaggeredGridLayoutManager.VERTICAL); layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); return layoutManager; }
Example 16
Source File: DownloadsScene.java From EhViewer with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_download, container, false); View content = ViewUtils.$$(view, R.id.content); mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view); FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller); mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout); TextView tip = (TextView) ViewUtils.$$(view, R.id.tip); mViewTransition = new ViewTransition(content, tip); Context context = getContext2(); AssertUtils.assertNotNull(content); Resources resources = context.getResources(); Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_download); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); tip.setCompoundDrawables(null, drawable, null, null); mAdapter = new DownloadAdapter(); mAdapter.setHasStableIds(true); mRecyclerView.setAdapter(mAdapter); mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL); mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())); mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT))); mRecyclerView.setDrawSelectorOnTop(true); mRecyclerView.setClipToPadding(false); mRecyclerView.setOnItemClickListener(this); mRecyclerView.setOnItemLongClickListener(this); mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM); mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener()); // Cancel change animation RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator(); if (itemAnimator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false); } int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval); int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h); int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v); MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV); mRecyclerView.addItemDecoration(decoration); decoration.applyPaddings(mRecyclerView); if (mInitPosition >= 0) { mRecyclerView.scrollToPosition(mInitPosition); mInitPosition = -1; } fastScroller.attachToRecyclerView(mRecyclerView); HandlerDrawable handlerDrawable = new HandlerDrawable(); handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent)); fastScroller.setHandlerDrawable(handlerDrawable); fastScroller.setOnDragHandlerListener(this); mFabLayout.setExpanded(false, false); mFabLayout.setHidePrimaryFab(true); mFabLayout.setAutoCancel(false); mFabLayout.setOnClickFabListener(this); addAboveSnackView(mFabLayout); updateView(); guide(); return view; }
Example 17
Source File: StaggeredGridRecyclerConfiguration.java From litho with Apache License 2.0 | 4 votes |
/** Use {@link #create()} instead. */ @Deprecated public StaggeredGridRecyclerConfiguration(int numSpans) { this(numSpans, StaggeredGridLayoutManager.VERTICAL, false); }
Example 18
Source File: BasicFunctions.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
protected final void configStaggerLayoutManager(UltimateRecyclerView rv, easyRegularAdapter ad) { StaggeredGridLayoutManager gaggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); rv.setLayoutManager(gaggeredGridLayoutManager); }
Example 19
Source File: HistoryScene.java From MHViewer with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_history, container, false); View content = ViewUtils.$$(view, R.id.content); mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view); FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller); TextView tip = (TextView) ViewUtils.$$(view, R.id.tip); mViewTransition = new ViewTransition(content, tip); Context context = getContext2(); AssertUtils.assertNotNull(context); Resources resources = context.getResources(); Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_history); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); tip.setCompoundDrawables(null, drawable, null, null); RecyclerViewTouchActionGuardManager guardManager = new RecyclerViewTouchActionGuardManager(); guardManager.setInterceptVerticalScrollingWhileAnimationRunning(true); guardManager.setEnabled(true); RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager(); mAdapter = new HistoryAdapter(); mAdapter.setHasStableIds(true); mAdapter = swipeManager.createWrappedAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter); final GeneralItemAnimator animator = new SwipeDismissItemAnimator(); animator.setSupportsChangeAnimations(false); mRecyclerView.setItemAnimator(animator); AutoStaggeredGridLayoutManager layoutManager = new AutoStaggeredGridLayoutManager( 0, StaggeredGridLayoutManager.VERTICAL); layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())); layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT))); mRecyclerView.setDrawSelectorOnTop(true); mRecyclerView.setClipToPadding(false); mRecyclerView.setOnItemClickListener(this); mRecyclerView.setOnItemLongClickListener(this); int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval); int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h); int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v); MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV); mRecyclerView.addItemDecoration(decoration); decoration.applyPaddings(mRecyclerView); guardManager.attachRecyclerView(mRecyclerView); swipeManager.attachRecyclerView(mRecyclerView); fastScroller.attachToRecyclerView(mRecyclerView); HandlerDrawable handlerDrawable = new HandlerDrawable(); handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent)); fastScroller.setHandlerDrawable(handlerDrawable); updateLazyList(); updateView(false); return view; }
Example 20
Source File: RecyclerViewFragment.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 4 votes |
private RecyclerView.LayoutManager getLayoutManager() { return new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); }