Java Code Examples for android.support.v7.widget.RecyclerView#getDecoratedBoundsWithMargins()

The following examples show how to use android.support.v7.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: TableDecoration.java    From ItemDecorationDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制View的边界
 * @param view 需要绘制的view
 */
private void draw(Canvas canvas, RecyclerView parent, View view) {
    canvas.save();
    int translationX = Math.round(view.getTranslationX());
    int translationY = Math.round(view.getTranslationY());
    int viewLeft = view.getLeft() + translationX;
    int viewRight = view.getRight() + translationX;
    int viewTop = view.getTop() + translationY;
    int viewBottom = view.getBottom() + translationY;
    parent.getDecoratedBoundsWithMargins(view, mBounds);
    drawLeft(canvas, mBounds, viewLeft);
    drawRight(canvas, mBounds, viewRight);
    drawTop(canvas, mBounds, viewTop);
    drawBottom(canvas, mBounds, viewBottom);
    canvas.restore();
}
 
Example 2
Source File: RecycleViewDivider.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state)
{
    canvas.save();
    int left = marginPx;
    int right = parent.getWidth() - marginPx;
    canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());

    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();
}
 
Example 3
Source File: ItemDecoration.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int leftWithMargin = convertDpToPx(56);
    final int 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(leftWithMargin, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 4
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 5
Source File: TableDecoration.java    From ItemDecorationDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 当最后一行没有充满时需要填充缺陷的地方
 */
private void drawLast(Canvas canvas, RecyclerView parent) {
    View lastView = parent.getChildAt(parent.getChildCount() - 1);
    int pos = parent.getChildAdapterPosition(lastView);
    if (isLastColumn((GridLayoutManager.LayoutParams) lastView.getLayoutParams(),pos)){
        return;
    }
    int translationX = Math.round(lastView.getTranslationX());
    int translationY = Math.round(lastView.getTranslationY());
    int viewLeft = lastView.getLeft() + translationX;
    int viewRight = lastView.getRight() + translationX;
    int viewTop = lastView.getTop() + translationY;
    int viewBottom = lastView.getBottom() + translationY;
    parent.getDecoratedBoundsWithMargins(lastView, mBounds);
    canvas.save();
    if (mManager.getOrientation() == LinearLayoutManager.VERTICAL) {
        int contentRight = parent.getRight() - parent.getPaddingRight() - Math.round(parent.getTranslationX());
        //空白区域上边缘
        mDivider.setBounds(mBounds.right, mBounds.top, contentRight, viewTop);
        mDivider.draw(canvas);
        //空白区域左边缘
        mDivider.setBounds(viewRight, viewTop, viewRight + mSize, mBounds.bottom);
        mDivider.draw(canvas);
    }else {
        int contentBottom = parent.getBottom()-parent.getPaddingBottom()-Math.round(parent.getTranslationY());
        //空白区域上边缘
        mDivider.setBounds(mBounds.left,viewBottom,mBounds.right,viewBottom+mSize);
        mDivider.draw(canvas);
        //空白区域左边缘
        mDivider.setBounds(mBounds.left,mBounds.bottom,viewLeft,contentBottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 6
Source File: DividerItemDecoration.java    From SimpleRecyclerView with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void drawHorizontalDivider(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);

    if (ignoreDrawDividerForCellTypes(parent, i)) {
      continue;
    }

    if (isLastRow(parent, child) && !isShowLastDivider) {
      continue;
    }

    parent.getDecoratedBoundsWithMargins(child, mBounds);
    final int bottom = mBounds.bottom;
    final int top = bottom - mDivider.getIntrinsicHeight();
    mDivider.setBounds(left, top, right, bottom);
    mDivider.draw(canvas);
  }
  canvas.restore();
}
 
Example 7
Source File: DividerItemDecoration.java    From NanoIconPack with Apache License 2.0 5 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++) {
        // Remove the last divider
        // @By_syk
        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(ViewCompat.getTranslationY(child));
            final int top = bottom - mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
        canvas.restore();
    }
 
Example 8
Source File: GroupItemDecoration.java    From group-recycler-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.getLayoutManager() == null) {
        return;
    }
    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);
        Object object = child.getTag(R.id.item_divider);
        if (object != null && object instanceof Drawable) {
            Drawable drawable = (Drawable) object;
            final int top = mBounds.top + Math.round(child.getTranslationX());
            final int bottom = mBounds.top + drawable.getIntrinsicHeight();
            drawable.setBounds(left, top, right, bottom);
            drawable.draw(canvas);
        }
    }
    canvas.restore();
}
 
Example 9
Source File: RecycleViewDivider.java    From AndroidUtilCode 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 childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (i == childCount - 1 && !mShowFooterDivider) continue;
        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 10
Source File: RecycleViewDivider.java    From AndroidUtilCode 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 childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (i == childCount - 1 && !mShowFooterDivider) continue;
        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 11
Source File: DividerItemDecoration.java    From PracticalRecyclerView with Apache License 2.0 5 votes vote down vote up
private void drawDividerVertical(Canvas canvas, RecyclerView parent, int left, int right,
                                 int 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);
}
 
Example 12
Source File: ShadowItemDecoration.java    From PracticalRecyclerView with Apache License 2.0 5 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();
    AbstractAdapter adapter = (AbstractAdapter) parent.getAdapter();

    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final int position = parent.getChildAdapterPosition(child);
        final int headerSize = adapter.getHeaderSize();

        if (adapter.isData(position)) {
            if (mStrategy.strategy(position - headerSize)) {
                parent.getDecoratedBoundsWithMargins(child, mBounds);
                final int bottom = child.getBottom();
                final int top = child.getTop();
                mShadowColor.setBounds(left, top, right, bottom);
                mShadowColor.draw(canvas);
            }
        }
    }
    canvas.restore();
}
 
Example 13
Source File: ShadowItemDecoration.java    From PracticalRecyclerView with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    AbstractAdapter adapter = (AbstractAdapter) parent.getAdapter();

    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final int position = parent.getChildAdapterPosition(child);
        final int headerSize = adapter.getHeaderSize();

        if (adapter.isData(position)) {
            if (mStrategy.strategy(position - headerSize)) {
                parent.getDecoratedBoundsWithMargins(child, mBounds);
                final int right = mBounds.right;
                final int left = mBounds.left;
                mShadowColor.setBounds(left, top, right, bottom);
                mShadowColor.draw(canvas);
            }
        }
    }
    canvas.restore();
}