Java Code Examples for androidx.recyclerview.widget.RecyclerView#getChildCount()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#getChildCount() .
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: IgnoreLastDividerItemDecorator.java From adamant-android with GNU General Public License v3.0 | 6 votes |
@Override public void onDraw(@NotNull Canvas canvas, @NotNull RecyclerView parent, @NotNull RecyclerView.State state) { int dividerLeft = parent.getPaddingLeft(); int dividerRight = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i <= childCount - 2; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int dividerTop = child.getBottom() + params.bottomMargin; int dividerBottom = dividerTop + mDivider.getIntrinsicHeight(); mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); mDivider.draw(canvas); } }
Example 2
Source File: SimpleDividerItemDecoration.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin; int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example 3
Source File: GridSpacingItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
private void drawHorizontal(Canvas canvas, RecyclerView parent) { int left = parent.getPaddingLeft(); int right = parent.getMeasuredWidth() - parent.getPaddingRight(); final int childSize = parent.getChildCount(); for (int i = 0; i < childSize; i++) { final View child = parent.getChildAt(i); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + layoutParams.bottomMargin; int bottom = top + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } }
Example 4
Source File: FilterUsersActivity.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { int width = parent.getWidth(); int top; int childCount = parent.getChildCount() - (single ? 0 : 1); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); View nextChild = i < childCount - 1 ? parent.getChildAt(i + 1) : null; int position = parent.getChildAdapterPosition(child); if (position < skipRows || child instanceof GraySectionCell || nextChild instanceof GraySectionCell) { continue; } top = child.getBottom(); canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(72), top, width - (LocaleController.isRTL ? AndroidUtilities.dp(72) : 0), top, Theme.dividerPaint); } }
Example 5
Source File: GridSpacingItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { final int top = parent.getPaddingTop(); final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); final int childSize = parent.getChildCount(); for (int i = 0; i < childSize; i++) { final View child = parent.getChildAt(i); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); final int left = child.getRight() + layoutParams.rightMargin; final int right = left + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } }
Example 6
Source File: DividerItemDecoration.java From klingar with Apache License 2.0 | 6 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); // Drawable width defines left/right padding. Drawable height defines divider height. final int left = parent.getPaddingStart() + divider.getIntrinsicWidth(); final int right = parent.getWidth() - parent.getPaddingEnd() - divider.getIntrinsicWidth(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getDecoratedBoundsWithMargins(child, bounds); final int bottom = bounds.bottom + Math.round(child.getTranslationY()); final int top = bottom - divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(canvas); } canvas.restore(); }
Example 7
Source File: DividerGridItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
public void drawHorizontal(Canvas c, RecyclerView parent) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int left = child.getLeft() - params.leftMargin; final int right = child.getRight() + params.rightMargin + mWidthDivider.getIntrinsicWidth(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + mWidthDivider.getIntrinsicHeight(); mWidthDivider.setBounds(left, top, right, bottom); mWidthDivider.draw(c); } }
Example 8
Source File: DividerItem.java From green_android with GNU General Public License v3.0 | 6 votes |
@Override public void onDrawOver(final Canvas c, final RecyclerView parent, final RecyclerView.State state) { final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; ++i) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)child.getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(c); } }
Example 9
Source File: GridSpacingItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { final int top = parent.getPaddingTop(); final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); final int childSize = parent.getChildCount(); for (int i = 0; i < childSize; i++) { final View child = parent.getChildAt(i); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); final int left = child.getRight() + layoutParams.rightMargin; final int right = left + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } }
Example 10
Source File: DividerItemDecoration.java From monero-wallet-android-app with MIT License | 5 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides. if (parent.getClipToPadding()) { left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(child.getTranslationY()); final int top = bottom - mDividerSize; mDividerPaint.setColor(mDividerColor); mDividerPaint.setStyle(Paint.Style.FILL); canvas.drawRect(left + mMarginStart, top + mMarginTop, right - mMarginEnd, bottom - mMarginBottom, mDividerPaint); } canvas.restore(); }
Example 11
Source File: MapLayerListFragment.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
@Override public void onBindDragView(View clickedView, View dragView) { LinearLayout clickedLayout = (LinearLayout) clickedView; View clickedHeader = clickedLayout.getChildAt(0); RecyclerView clickedRecyclerView = (RecyclerView) clickedLayout.getChildAt(1); View dragHeader = dragView.findViewById(R.id.drag_header); ScrollView dragScrollView = dragView.findViewById(R.id.drag_scroll_view); LinearLayout dragLayout = dragView.findViewById(R.id.drag_list); dragLayout.removeAllViews(); ((TextView) dragHeader.findViewById(R.id.text)).setText(((TextView) clickedHeader.findViewById(R.id.text)).getText()); ((TextView) dragHeader.findViewById(R.id.item_count)).setText(((TextView) clickedHeader.findViewById(R.id.item_count)).getText()); for (int i = 0; i < clickedRecyclerView.getChildCount(); i++) { View mapItemView = View.inflate(dragView.getContext(), R.layout.column_item, null); ((TextView) mapItemView.findViewById(R.id.text)).setText(((TextView) clickedRecyclerView.getChildAt(i).findViewById(R.id.text)).getText()); dragLayout.addView(mapItemView); if (i == 0) { dragScrollView.setScrollY(-clickedRecyclerView.getChildAt(i).getTop()); } } dragView.setPivotY(0); dragView.setPivotX(clickedView.getMeasuredWidth() / 2); }
Example 12
Source File: DividerGridItemDecoration.java From RvHelper with Apache License 2.0 | 5 votes |
public void drawVertical(Canvas c, RecyclerView parent) { final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getTop() - params.topMargin; final int bottom = child.getBottom() + params.bottomMargin; final int left = child.getRight() + params.rightMargin; final int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example 13
Source File: StickyHeaderDecoration.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
protected int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) { int headerHeight = getHeaderHeightForLayout(header); int top = getChildY(parent, child) - headerHeight; if (sticky && layoutPos == 0) { final int count = parent.getChildCount(); final long currentId = adapter.getHeaderId(adapterPos); // find next view with header and compute the offscreen push if needed for (int i = 1; i < count; i++) { int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(translatedChildPosition(parent, i))); if (adapterPosHere != RecyclerView.NO_POSITION) { long nextId = adapter.getHeaderId(adapterPosHere); if (nextId != currentId) { final View next = parent.getChildAt(translatedChildPosition(parent, i)); final int offset = getChildY(parent, next) - (headerHeight + getHeader(parent, adapter, adapterPosHere).itemView.getHeight()); if (offset < 0) { return offset; } else { break; } } } } if (sticky) top = Math.max(0, top); } return top; }
Example 14
Source File: SimpleDividerDecoration.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { int childCount = parent.getChildCount(); int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); for (int i = 0; i < childCount - 1; i++) { View view = parent.getChildAt(i); float top = view.getBottom(); float bottom = view.getBottom() + dividerHeight; c.drawRect(left, top, right, bottom, dividerPaint); } }
Example 15
Source File: DividerItemDecoration.java From FChat with MIT License | 5 votes |
public void drawVertical(Canvas c, RecyclerView parent) { final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example 16
Source File: StickyHeaderDecoration.java From header-decor with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = adapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
Example 17
Source File: DoubleHeaderDecoration.java From header-decor with Apache License 2.0 | 5 votes |
private int getSubHeaderTop(@NonNull RecyclerView parent, @NonNull View child, @NonNull View header, @NonNull View subHeader, int adapterPos, int layoutPos) { int top = getAnimatedTop(child) - getSubHeaderHeightForLayout(subHeader); if (isFirstValidChild(layoutPos, parent)) { final int count = parent.getChildCount(); final long currentHeaderId = adapter.getHeaderId(adapterPos); final long currentSubHeaderId = adapter.getSubHeaderId(adapterPos); // find next view with sub-header and compute the offscreen push if needed for (int i = layoutPos + 1; i < count; i++) { final View next = parent.getChildAt(i); int adapterPosHere = parent.getChildAdapterPosition(next); if (adapterPosHere != RecyclerView.NO_POSITION) { final long nextHeaderId = adapter.getHeaderId(adapterPosHere); final long nextSubHeaderId = adapter.getSubHeaderId(adapterPosHere); if ((nextSubHeaderId != currentSubHeaderId)) { int headersHeight = getSubHeaderHeightForLayout(subHeader) + getSubHeader(parent, adapterPosHere).itemView.getHeight(); if (nextHeaderId != currentHeaderId) { headersHeight += getHeader(parent, adapterPosHere).itemView.getHeight(); } final int offset = getAnimatedTop(next) - headersHeight; if (offset < header.getHeight()) { return offset; } else { break; } } } } } return Math.max(header.getHeight(), top); }
Example 18
Source File: FlexibleItemDecoration.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") protected void drawVertical(Canvas canvas, RecyclerView parent) { canvas.save(); final int left; final int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } final int itemCount = parent.getChildCount(); for (int i = 0; i < itemCount - mDividerOnLastItem; i++) { final View child = parent.getChildAt(i); RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child); if (shouldDrawDivider(viewHolder)) { parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(child.getTranslationY()); final int top = bottom - mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } } canvas.restore(); }
Example 19
Source File: ListRecyclerView.java From NekoSMS with GNU General Public License v3.0 | 5 votes |
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin + (int)child.getTranslationY(); int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example 20
Source File: GridSpacingItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
/***/ private void drawGrideview1(Canvas canvas, RecyclerView parent) { GridLayoutManager linearLayoutManager = (GridLayoutManager) parent.getLayoutManager(); int childSize = parent.getChildCount(); int top, bottom, left, right, spancount; spancount = linearLayoutManager.getSpanCount(); for (int i = 0; i < childSize; i++) { final View child = parent.getChildAt(i); //画横线 RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); top = child.getBottom() + layoutParams.bottomMargin; bottom = top + space; left = layoutParams.leftMargin + child.getPaddingLeft() + space; right = child.getMeasuredWidth() * (i + 1) + left + space * i; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } //画竖线 top = (layoutParams.topMargin + space) * (i / linearLayoutManager.getSpanCount() + 1); bottom = (child.getMeasuredHeight() + space) * (i / linearLayoutManager.getSpanCount() + 1) + space; left = child.getRight() + layoutParams.rightMargin; right = left + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } //画上缺失的线框 if (i < spancount) { top = child.getTop() + layoutParams.topMargin; bottom = top + space; left = (layoutParams.leftMargin + space) * (i + 1); right = child.getMeasuredWidth() * (i + 1) + left + space * i; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } if (i % spancount == 0) { top = (layoutParams.topMargin + space) * (i / linearLayoutManager.getSpanCount() + 1); bottom = (child.getMeasuredHeight() + space) * (i / linearLayoutManager.getSpanCount() + 1) + space; left = child.getLeft() + layoutParams.leftMargin; right = left + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } } }