Java Code Examples for androidx.recyclerview.widget.RecyclerView#getDecoratedBoundsWithMargins()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getDecoratedBoundsWithMargins() . 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: DividerItemDecoration.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
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 - 1; i++) {
        final View child = parent.getChildAt(i);
        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 2
Source File: DividerItemDecoration.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
private 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 childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0);
    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 - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 3
Source File: CustomDividerItemDecoration.java    From Android-skin-support with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private 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 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(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 4
Source File: SimpleDividerItemDecoration.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(leftPadding, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        right = parent.getWidth();
    }

    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 - 1;
        divider.setBounds(leftPadding, top, right, bottom);
        divider.draw(canvas);
    }
    canvas.restore();
}
 
Example 5
Source File: GridDividerDecoration.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
  final int itemCount = parent.getAdapter().getItemCount();
  final int childCount = parent.getChildCount();
  final int lastRowChildCount = getLastRowChildCount(itemCount);
  for (int i = 0; i < childCount; i++) {
    final View child = parent.getChildAt(i);

    if (isChildInLastRow(parent, child, itemCount, lastRowChildCount)) {
      continue;
    }

    parent.getDecoratedBoundsWithMargins(child, bounds);
    final int y = bounds.bottom;
    final int startX = bounds.left;
    final int stopX = bounds.right;
    canvas.drawLine(startX, y, stopX, y, dividerPaint);
  }
}
 
Example 6
Source File: GridDividerDecoration.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
  final int childCount = parent.getChildCount();
  final boolean isRTL =
      ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_RTL;
  for (int i = 0; i < childCount; i++) {
    final View child = parent.getChildAt(i);

    if (isChildInLastColumn(parent, child)) {
      continue;
    }

    parent.getDecoratedBoundsWithMargins(child, bounds);
    final int x = isRTL ? bounds.left : bounds.right;
    final int startY = bounds.top;
    final int stopY = bounds.bottom;
    canvas.drawLine(x, startY, x, stopY, dividerPaint);
  }
}
 
Example 7
Source File: DividerItemDecoration.java    From klingar with Apache License 2.0 6 votes vote down vote up
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 8
Source File: DividerItemDecoration.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
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 9
Source File: SelectiveDividerItemDecoration.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();

    int left;
    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();
    }

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (isDecorated(i)) {
            View child = parent.getChildAt(i);
            parent.getDecoratedBoundsWithMargins(child, mBounds);
            int bottom = mBounds.bottom + Math.round(child.getTranslationY());
            int top = bottom - mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }

    canvas.restore();
}
 
Example 10
Source File: InstallerXAdapterDividerItemDecoration.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
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();
    RecyclerView.Adapter adapter = parent.getAdapter();
    final int itemCount = adapter == null ? -1 : adapter.getItemCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int adapterPosition = parent.getChildAdapterPosition(child);
        if (adapterPosition == 0 || adapterPosition == itemCount - 1)
            continue;

        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 11
Source File: OptionsItemDecoration.java    From FeatureAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawViewImpl(Canvas canvas, View view, RecyclerView.ViewHolder holder, RecyclerView parent, RecyclerView.State state) {
  canvas.save();
  parent.getDecoratedBoundsWithMargins(view, tempBounds);
  divider.setBounds(tempBounds.left, tempBounds.bottom - divider.getIntrinsicHeight(), tempBounds.right, tempBounds.bottom);
  divider.draw(canvas);
  canvas.restore();
}
 
Example 12
Source File: AdvancedDividerItemDecoration.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    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 childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (!hasDivider(parent, child))
            continue;
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.setAlpha((int) (child.getAlpha() * 255));
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 13
Source File: SuperDividerItemDecoration.java    From RecyclerViewHelper with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a horizontal line.
 *
 * @param canvas Canvas
 * @param parent RecyclerView
 */
private void drawHorizontalLine(Canvas canvas, RecyclerView parent) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager == null || mDivider == null) {
        return;
    }

    canvas.save();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (isLastRow(child, parent)) {
            continue;
        }

        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int left = mBounds.left;
        final int right = mBounds.right;
        int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        // Horizontal GridLayout display in the left, margin top or bottom mDividerHeight / 2.
        if (mOrientation == HORIZONTAL && layoutManager instanceof GridLayoutManager) {
            bottom += mDividerHeight / 2;
        }
        final int top = bottom - mDividerHeight;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 14
Source File: EventItemDecorator.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getLayoutManager() == null) {
        return;
    }

    c.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        c.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, bounds);

        int position = parent.getChildAdapterPosition(child);
        if (parent.getAdapter().getItemViewType(position) == EventListAdapter.ITEM_TYPE_HEADER ||
            parent.getAdapter().getItemViewType(position + 1) == EventListAdapter.ITEM_TYPE_HEADER ||
            position == state.getItemCount() - 1) {
            continue;
        }

        final int bottom = bounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
    c.restore();
}
 
Example 15
Source File: FlexibleItemDecoration.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: DividerItemDecorationEx.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int left;
    int right;
    if (mDividerPadding != 0) {
        left = mDividerPadding;
        right = parent.getWidth() - mDividerPadding;
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else 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();
    }

    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; ++i) {
        View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, this.mBounds);
        int bottom = this.mBounds.bottom + Math.round(child.getTranslationY());
        int top = bottom - this.mDivider.getIntrinsicHeight();
        this.mDivider.setBounds(left, top, right, bottom);
        this.mDivider.draw(canvas);
    }

    canvas.restore();
}