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

The following examples show how to use android.support.v7.widget.RecyclerView#getClipToPadding() . 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 NanoIconPack with Apache License 2.0 6 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();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 2
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 3
Source File: CustomDividerItemDecoration.java    From Android-skin-support with MIT License 6 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();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: RecycleViewDivider.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
protected 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();
    for (int i = 0; i < childCount; i++) {
        if (i == childCount - 1 && !mShowFooterDivider) continue;
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.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 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();
    for (int i = 0; i < childCount; i++) {
        if (i == childCount - 1 && !mShowFooterDivider) continue;
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        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
@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);
        if (adapter.isData(position)) {
            drawDividerVertical(canvas, parent, left, right, i);
        }
    }
    canvas.restore();
}
 
Example 12
Source File: DividerItemDecoration.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);
        if (adapter.isData(position)) {
            drawDividerHorizontal(canvas, parent, top, bottom, i);
        }
    }
    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 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 14
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();
}
 
Example 15
Source File: StickHeaderDecoration.java    From ItemDecorationDemo with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent,
                       @NonNull RecyclerView.State state) {
    RecyclerView.Adapter adapter = parent.getAdapter();
    if (adapter == null || !(adapter instanceof StickProvider)) {
        return;
    }
    int itemCount = adapter.getItemCount();
    if (itemCount == 1) {
        return;
    }
    //找到当前的StickHeader对应的position
    int currStickPos = currStickPos(parent);
    if (currStickPos == -1) {
        return;
    }
    c.save();
    if (parent.getClipToPadding()) {
        //考虑padding的情况
        c.clipRect(parent.getPaddingLeft(), parent.getPaddingTop(),
                parent.getWidth() - parent.getPaddingRight(),
                parent.getHeight() - parent.getPaddingBottom());
    }
    int currStickType = adapter.getItemViewType(currStickPos);
    //当前显示的StickHeader相应的ViewHolder,先看有没有缓存
    RecyclerView.ViewHolder currHolder = mViewMap.get(currStickType);
    if (currHolder == null) {
        //没有缓存则新生成
        currHolder = adapter.createViewHolder(parent, currStickType);
        //主动测量并布局
        measure(currHolder.itemView, parent);
        mViewMap.put(currStickType, currHolder);
    }
    //寻找下一个StickHeader
    RecyclerView.ViewHolder nextStickHolder = nextStickHolder(parent, currStickPos);
    if (nextStickHolder != null) {
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) currHolder.itemView.getLayoutParams();
        int bottom = parent.getPaddingTop() + params.topMargin + currHolder.itemView.getMeasuredHeight();
        int nextStickTop = nextStickHolder.itemView.getTop();
        //下一个StickHeader如果顶部碰到了当前StickHeader的屁股,那么将当前的向上推
        if (nextStickTop < bottom && nextStickTop > 0) {
            c.translate(0, nextStickTop - bottom);
        }
    }
    adapter.bindViewHolder(currHolder, currStickPos);
    c.translate(currHolder.itemView.getLeft(), currHolder.itemView.getTop());
    currHolder.itemView.draw(c);
    c.restore();
}
 
Example 16
Source File: DividerLinearItemDecoration.java    From FlexItemDecoration with Apache License 2.0 4 votes vote down vote up
private boolean isClipToPadding(RecyclerView parent) {
	return parent.getClipToPadding();
}