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

The following examples show how to use android.support.v7.widget.RecyclerView#getPaddingRight() . 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 ForPDA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(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 2
Source File: DividerItem.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@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 3
Source File: SimpleDividerItemDecoration.java    From AndroidSchool with Apache License 2.0 6 votes vote down vote up
@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;
        if (mDrawTopDivider) {
            top = child.getTop();
        } else {
            top = child.getBottom() + params.bottomMargin;
        }
        int bottom = top + mDivider.getIntrinsicHeight();

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 4
Source File: SimpleDivider.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: VerticalDividerDecoration.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, 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 + 25;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 6
Source File: DividerItemDecoration.java    From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 7
Source File: DividerDecoration.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final 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();
        final int top = child.getBottom() + layoutParams.bottomMargin;
        final int bottom = top + mDividerHeight;
        if (mDivider != null) {
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
        if (mPaint != null) {
            canvas.drawRect(left, top, right, bottom, mPaint);
        }
    }
}
 
Example 8
Source File: DividerItemDecoration.java    From chaoli-forum-for-android-2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(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 9
Source File: FloatingBarItemDecoration.java    From ContactsList with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, 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();
        int position = params.getViewAdapterPosition();
        if (!mList.containsKey(position)) {
            continue;
        }
        drawTitleArea(c, left, right, child, params, position);
    }
}
 
Example 10
Source File: DividerRVDecoration.java    From SHSwipeRefreshLayout with MIT License 6 votes vote down vote up
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);
        android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
        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 11
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 12
Source File: DividerItemDecoration.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mDivider == null) {
        super.onDrawOver(c, parent, state);
        return;
    }

    // Initialization needed to avoid compiler warning
    int left = 0, right = 0, top = 0, bottom = 0, size;
    int orientation = mOrientation != -1 ? mOrientation : getOrientation(parent);
    int childCount = parent.getChildCount();

    if (orientation == LinearLayoutManager.VERTICAL) {
        size = mDivider.getIntrinsicHeight();
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
    } else { //horizontal
        size = mDivider.getIntrinsicWidth();
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
    }

    for (int i = 1; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        if (orientation == LinearLayoutManager.VERTICAL) {
            top = child.getTop() - params.topMargin - size;
            bottom = top + size;
        } else { //horizontal
            left = child.getLeft() - params.leftMargin;
            right = left + size;
        }
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }

    // show last divider
}
 
Example 13
Source File: DividerItemDecoration.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft() + MusicUtils.getDPFromPixel( mLeftMargin);
    final int right = parent.getWidth() - parent.getPaddingRight() - MusicUtils.getDPFromPixel(mRightMargin);

    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 14
Source File: DividedItemDecoration.java    From JalanJalan with Do What The F*ck You Want To Public License 5 votes vote down vote up
private 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 15
Source File: DividedItemDecoration.java    From example with Apache License 2.0 5 votes vote down vote up
private 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: DividerItemDecoration.java    From RecyclerViewRenderers with Apache License 2.0 5 votes vote down vote up
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 17
Source File: DividerItemDecoration.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
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 + this.divider.getIntrinsicHeight();
        this.divider.setBounds(left, top, right, bottom);
        this.divider.draw(c);
    }
}
 
Example 18
Source File: SuspensionDecoration.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, 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();
        int position = params.getViewLayoutPosition();
        position -= getHeaderViewCount();
        //pos为1,size为1,1>0? true
        if (position < mDatas.size() && mDatas.size() > 0){//保证不越界
            if (mDatas == null || position > mDatas.size() - 1 || position < 0 || !mDatas.get(position).isShowSuspension()) {
                continue;//越界
            }
            //我记得Rv的item position在重置时可能为-1.保险点判断一下吧
            if (position == 0) {//等于0肯定要有title的
                drawTitleArea(c, left, right, child, params, position);

            } else {//其他的通过判断
                if (null != mDatas.get(position).getSuspensionTag() && !mDatas.get(position).getSuspensionTag().equals(mDatas.get(position - 1).getSuspensionTag())) {
                    //不为空 且跟前一个tag不一样了,说明是新的分类,也要title
                    drawTitleArea(c, left, right, child, params, position);
                } else {
                    //none
                }
            }
        }

    }
}
 
Example 19
Source File: ClassifyView.java    From ClassifyView with Apache License 2.0 4 votes vote down vote up
/**
 * If user drags the view to the edge, trigger a scroll if necessary.
 */
private boolean scrollIfNecessary() {
    RecyclerView recyclerView = null;
    if ((mRegion & IN_MAIN_REGION) != 0) {
        recyclerView = mMainRecyclerView;
    }
    if ((mRegion & IN_SUB_REGION) != 0) {
        recyclerView = mSubRecyclerView;
    }
    if (recyclerView == null) return false;
    final long now = System.currentTimeMillis();
    final long scrollDuration = mDragScrollStartTimeInMs
            == Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs;
    RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();

    int scrollX = 0;
    int scrollY = 0;
    if (lm.canScrollHorizontally()) {
        int curX = (int) (mSelectedStartX + mDx);
        final int leftDiff = curX - mEdgeWidth - recyclerView.getPaddingLeft();
        if (mDx < 0 && leftDiff < 0) {
            scrollX = leftDiff;
        } else if (mDx > 0) {
            final int rightDiff =
                    curX + mSelected.getWidth() + mEdgeWidth - (recyclerView.getWidth() - recyclerView.getPaddingRight());
            if (rightDiff > 0) {
                scrollX = rightDiff;
            }
        }
    }
    if (lm.canScrollVertically()) {
        int curY = (int) (mSelectedStartY + mDy);
        final int topDiff = curY - mEdgeWidth - recyclerView.getPaddingTop();
        if (mDy < 0 && topDiff < 0) {
            scrollY = topDiff;
        } else if (mDy > 0) {
            final int bottomDiff = curY + mSelected.getHeight() + mEdgeWidth -
                    (recyclerView.getHeight() - recyclerView.getPaddingBottom());
            if (bottomDiff > 0) {
                scrollY = bottomDiff;
            }
        }
    }
    if (scrollX != 0) {
        scrollX = interpolateOutOfBoundsScroll(recyclerView,
                mSelected.getWidth(), scrollX,
                recyclerView.getWidth(), scrollDuration);
    }
    if (scrollY != 0) {
        scrollY = interpolateOutOfBoundsScroll(recyclerView,
                mSelected.getHeight(), scrollY,
                recyclerView.getHeight(), scrollDuration);
    }
    if (scrollX != 0 || scrollY != 0) {
        if (mDragScrollStartTimeInMs == Long.MIN_VALUE) {
            mDragScrollStartTimeInMs = now;
        }
        recyclerView.scrollBy(scrollX, scrollY);
        return true;
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    return false;
}
 
Example 20
Source File: SearchDivider.java    From MeiZiNews with MIT License 4 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (divider == null) {
        super.onDraw(c, parent, state);
        return;
    }

    int left = 0;
    int right = 0;
    int top = 0;
    int bottom = 0;

    final int orientation = getOrientation(parent);
    final int childCount = parent.getChildCount();

    final boolean vertical = orientation == LinearLayoutManager.VERTICAL;
    final int size;
    if (vertical) {
        size = dividerHeight;
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
    } else {
        size = dividerWidth;
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
    }

    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int position = params.getViewLayoutPosition();
        if (position == 0) {
            continue;
        }
        if (vertical) {
            top = child.getTop() - params.topMargin - size;
            bottom = top + size;
        } else {
            left = child.getLeft() - params.leftMargin - size;
            right = left + size;
        }
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
}