Java Code Examples for androidx.recyclerview.widget.RecyclerView#getMeasuredWidth()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#getMeasuredWidth() .
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: 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 2
Source File: GridSpacingItemDecoration.java From MyBookshelf 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 3
Source File: GroupItemDecoration.java From CalendarView with Apache License 2.0 | 6 votes |
/** * 绘制分组Group * * @param c Canvas * @param parent RecyclerView */ protected void onDrawGroup(Canvas c, RecyclerView parent) { int paddingLeft = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int top, bottom; int count = parent.getChildCount(); for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int key = params.getViewLayoutPosition(); if (mGroup.containsKey(key)) { top = child.getTop() - params.topMargin - mGroupHeight; bottom = top + mGroupHeight; c.drawRect(paddingLeft, top, right, bottom, mBackgroundPaint); String group = mGroup.get(params.getViewLayoutPosition()).toString(); float x; float y = top + mTextBaseLine; if (isCenter) { x = parent.getMeasuredWidth() / 2 - getTextX(group); } else { x = mPaddingLeft; } c.drawText(group, x, y, mTextPaint); } } }
Example 4
Source File: GridMenu.java From gridmenu with MIT License | 5 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); measureItemView(view, parent); int viewWidth = view.getMeasuredWidth(); if (spanCount * viewWidth < parent.getMeasuredWidth()) { int emptySpacePx = parent.getMeasuredWidth() - spanCount * viewWidth; outRect.left = outRect.right = emptySpacePx / (2 * spanCount); } }
Example 5
Source File: CarouselItemDecoration.java From CarouselView with MIT License | 5 votes |
@Override public void getItemOffsets(@NonNull final Rect outRect, @NonNull final View view, @NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); outRect.right = this.width > 0 ? this.spacing / 2 : this.spacing; outRect.left = this.width > 0 ? this.spacing / 2 : 0; if ((state.getItemCount() - 1 == parent.getChildLayoutPosition(view))) { outRect.right = this.width > 0 ? ((parent.getMeasuredWidth() / 2) - (this.width / 2)) : 0; } if (parent.getChildLayoutPosition(view) == 0) { outRect.left = this.width > 0 ? ((parent.getMeasuredWidth() / 2) - (this.width / 2)) : 0; } }
Example 6
Source File: ColorItemDecoration.java From FastAdapter with MIT License | 5 votes |
private void drawHorizontal(Canvas canvas, RecyclerView parent) { final int left = parent.getPaddingLeft(); final int right = parent.getMeasuredWidth() - parent.getPaddingRight(); 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 top = child.getBottom() + layoutParams.bottomMargin; final int bottom = top + mDividerHeight; if (mPaint != null) { canvas.drawRect(left + mMarginLeft, top, right, bottom, mPaint); } } }
Example 7
Source File: OrientationStateHorizontalBottom.java From LoopBar with MIT License | 5 votes |
@Override public boolean isItemsFitOnScreen(RecyclerView recyclerView, int itemsSize) { calcItemWidth(recyclerView); int itemsWidth = itemWidth * (itemsSize); int containerWidth = recyclerView.getMeasuredWidth(); return containerWidth >= itemsWidth; }
Example 8
Source File: GroupItemDecoration.java From CalendarView with Apache License 2.0 | 4 votes |
/** * 绘制悬浮组 * * @param c Canvas * @param parent RecyclerView */ protected void onDrawOverGroup(Canvas c, RecyclerView parent) { int firstVisiblePosition = ((LinearLayoutManager) parent.getLayoutManager()).findFirstVisibleItemPosition(); if (firstVisiblePosition == RecyclerView.NO_POSITION) { return; } Group group = getCroup(firstVisiblePosition); if (group == null) return; String groupTitle = group.toString(); if (TextUtils.isEmpty(groupTitle)) { return; } boolean isRestore = false; Group nextGroup = getCroup(firstVisiblePosition + 1); if (nextGroup != null && !group.equals(nextGroup)) { //说明是当前组最后一个元素,但不一定碰撞了 View child = parent.findViewHolderForAdapterPosition(firstVisiblePosition).itemView; if (child.getTop() + child.getMeasuredHeight() < mGroupHeight) { //进一步检测碰撞 c.save();//保存画布当前的状态 isRestore = true; c.translate(0, child.getTop() + child.getMeasuredHeight() - mGroupHeight); } } int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int top = parent.getPaddingTop(); int bottom = top + mGroupHeight; c.drawRect(left, top, right, bottom, mBackgroundPaint); float x; float y = top + mTextBaseLine; if (isCenter) { x = parent.getMeasuredWidth() / 2 - getTextX(groupTitle); } else { x = mPaddingLeft; } c.drawText(groupTitle, x, y, mTextPaint); if (isRestore) { //还原画布为初始状态 c.restore(); } }