Java Code Examples for androidx.recyclerview.widget.GridLayoutManager#getSpanSizeLookup()
The following examples show how to use
androidx.recyclerview.widget.GridLayoutManager#getSpanSizeLookup() .
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: FlexibleDividerDecoration.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * @param manager * @param position * @return */ protected int positionTotalSpanSize(GridLayoutManager manager, int position) { int totalSpanSize = 0; GridLayoutManager.SpanSizeLookup spanSizeLookup = manager.getSpanSizeLookup(); int spanCount = manager.getSpanCount(); int groupIndex = spanSizeLookup.getSpanGroupIndex(position, spanCount); for (int i = position; i >= 0; i--) { int thisGroupIndex = spanSizeLookup.getSpanGroupIndex(i, spanCount); if (thisGroupIndex == groupIndex) { totalSpanSize += spanSizeLookup.getSpanSize(i); } else { break; } } return totalSpanSize; }
Example 2
Source File: FlexibleDividerDecoration.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * In the case mShowLastDivider = false, * Returns offset for how many views we don't have to draw a divider for, * for LinearLayoutManager it is as simple as not drawing the last child divider, * but for a GridLayoutManager it needs to take the span count for the last items into account * until we use the span count configured for the grid. * * @param parent RecyclerView * @return offset for how many views we don't have to draw a divider or 1 if its a * LinearLayoutManager */ private int getLastDividerOffset(RecyclerView parent) { if (parent.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); int spanCount = layoutManager.getSpanCount(); int itemCount = parent.getAdapter().getItemCount(); for (int i = itemCount - 1; i >= 0; i--) { if (spanSizeLookup.getSpanIndex(i, spanCount) == 0) { return itemCount - i; } } } return 1; }
Example 3
Source File: FlexibleDividerDecoration.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * @param manager * @param position * @return */ protected int positionTotalSpanSize(GridLayoutManager manager, int position) { int totalSpanSize = 0; GridLayoutManager.SpanSizeLookup spanSizeLookup = manager.getSpanSizeLookup(); int spanCount = manager.getSpanCount(); int groupIndex = spanSizeLookup.getSpanGroupIndex(position, spanCount); for (int i = position; i >= 0; i--) { int thisGroupIndex = spanSizeLookup.getSpanGroupIndex(i, spanCount); if (thisGroupIndex == groupIndex) { totalSpanSize += spanSizeLookup.getSpanSize(i); } else { break; } } return totalSpanSize; }
Example 4
Source File: FlexibleDividerDecoration.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * In the case mShowLastDivider = false, * Returns offset for how many views we don't have to draw a divider for, * for LinearLayoutManager it is as simple as not drawing the last child divider, * but for a GridLayoutManager it needs to take the span count for the last items into account * until we use the span count configured for the grid. * * @param parent RecyclerView * @return offset for how many views we don't have to draw a divider or 1 if its a * LinearLayoutManager */ private int getLastDividerOffset(RecyclerView parent) { if (parent.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); int spanCount = layoutManager.getSpanCount(); int itemCount = parent.getAdapter().getItemCount(); for (int i = itemCount - 1; i >= 0; i--) { if (spanSizeLookup.getSpanIndex(i, spanCount) == 0) { return itemCount - i; } } } return 1; }
Example 5
Source File: BaseRecyclerViewAdapter.java From GetApk with MIT License | 6 votes |
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { if (recyclerView.getLayoutManager() instanceof GridLayoutManager){ final GridLayoutManager manager = (GridLayoutManager) recyclerView.getLayoutManager(); if (manager.getSpanSizeLookup() instanceof GridLayoutManager.DefaultSpanSizeLookup){ manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { int type = itemArray.get(position).getDataType(); if (type >= TYPE_HEADER){ return manager.getSpanCount(); //宽度为整个recycler的宽度 } return 1; } }); } } }
Example 6
Source File: BaseRecyclerAdapter.java From NewFastFrame with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(final RecyclerView recyclerView) { this.display = recyclerView; RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup(); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { BaseRecyclerAdapter wrapperAdapter = (BaseRecyclerAdapter) recyclerView.getAdapter(); if (isFullSpanType(wrapperAdapter.getItemViewType(position))) { return gridLayoutManager.getSpanCount(); } else if (spanSizeLookup != null) { return spanSizeLookup.getSpanSize(position - getItemUpCount()); } return 1; } }); } }
Example 7
Source File: AdapterWrapper.java From SwipeRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { mAdapter.onAttachedToRecyclerView(recyclerView); RecyclerView.LayoutManager lm = recyclerView.getLayoutManager(); if (lm instanceof GridLayoutManager) { final GridLayoutManager glm = (GridLayoutManager)lm; final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup(); glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (isHeaderOrFooter(position)) return glm.getSpanCount(); if (originLookup != null) return originLookup.getSpanSize(position); return 1; } }); } }
Example 8
Source File: SwipeRecyclerView.java From SwipeRecyclerView with Apache License 2.0 | 6 votes |
@Override public void setLayoutManager(LayoutManager layoutManager) { if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager)layoutManager; final GridLayoutManager.SpanSizeLookup spanSizeLookupHolder = gridLayoutManager.getSpanSizeLookup(); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (mAdapterWrapper.isHeader(position) || mAdapterWrapper.isFooter(position)) { return gridLayoutManager.getSpanCount(); } if (spanSizeLookupHolder != null) { return spanSizeLookupHolder.getSpanSize(position - getHeaderCount()); } return 1; } }); } super.setLayoutManager(layoutManager); }
Example 9
Source File: ExpandableAdapter.java From SwipeRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { RecyclerView.LayoutManager lm = recyclerView.getLayoutManager(); if (lm instanceof GridLayoutManager) { final GridLayoutManager glm = (GridLayoutManager)lm; final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup(); glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (isParentItem(position)) return glm.getSpanCount(); if (originLookup != null) return originLookup.getSpanSize(position); return 1; } }); } }
Example 10
Source File: GridDividerDecoration.java From pandora with Apache License 2.0 | 5 votes |
private int getGroupIndex(int position, RecyclerView parent) { if (parent.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager(); GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup(); int spanCount = layoutManager.getSpanCount(); return spanSizeLookup.getSpanGroupIndex(position, spanCount); } return position; }
Example 11
Source File: DefaultEndlessRecyclerAdapter.java From GestureViews with Apache License 2.0 | 5 votes |
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager(); spanCount = gridManager.getSpanCount(); originalSpanLookup = gridManager.getSpanSizeLookup(); gridManager.setSpanSizeLookup(spanSizes); } }
Example 12
Source File: GridSpacingDecoration.java From Audinaut with GNU General Public License v3.0 | 4 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int spacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, SPACING, view.getResources().getDisplayMetrics()); int halfSpacing = spacing / 2; int childCount = parent.getChildCount(); int childIndex = parent.getChildAdapterPosition(view); // Not an actual child (ie: during delete event) if (childIndex == -1) { return; } int spanCount = getTotalSpan(parent); int spanIndex = childIndex % spanCount; // If we can, use the SpanSizeLookup since headers screw up the index calculation RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup(); if (spanSizeLookup != null) { spanIndex = spanSizeLookup.getSpanIndex(childIndex, spanCount); } } int spanSize = getSpanSize(parent, childIndex); /* INVALID SPAN */ if (spanCount < 1 || spanSize > 1) return; int margins = 0; if (view instanceof UpdateView) { View firstChild = ((ViewGroup) view).getChildAt(0); ViewGroup.LayoutParams layoutParams = firstChild.getLayoutParams(); if (layoutParams instanceof LinearLayout.LayoutParams) { margins = ((LinearLayout.LayoutParams) layoutParams).bottomMargin; } else if (layoutParams instanceof FrameLayout.LayoutParams) { margins = ((FrameLayout.LayoutParams) layoutParams).bottomMargin; } } int doubleMargins = margins * 2; outRect.top = halfSpacing - margins; outRect.bottom = halfSpacing - margins; outRect.left = halfSpacing - margins; outRect.right = halfSpacing - margins; if (isTopEdge(childIndex, spanIndex, spanCount)) { outRect.top = spacing - doubleMargins; } if (isLeftEdge(spanIndex)) { outRect.left = spacing - doubleMargins; } if (isRightEdge(spanIndex, spanCount)) { outRect.right = spacing - doubleMargins; } if (isBottomEdge(childIndex, childCount, spanCount)) { outRect.bottom = spacing - doubleMargins; } }