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

The following examples show how to use android.support.v7.widget.RecyclerView#getChildAt() . 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: LineDecoration.java    From Android with MIT License 6 votes vote down vote up
@Override
public void onDrawOver(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 + mDrawable.getIntrinsicHeight();
        mDrawable.setBounds(left, top, right, bottom);
        mDrawable.draw(c);
    }
}
 
Example 2
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 3
Source File: StickyHeaderDecoration.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
  final int count = parent.getChildCount();

  for (int layoutPos = 0; layoutPos < count; layoutPos++) {
    final View child = parent.getChildAt(translatedChildPosition(parent, layoutPos));

    final int adapterPos = parent.getChildAdapterPosition(child);

    if (adapterPos != RecyclerView.NO_POSITION && ((layoutPos == 0 && sticky) || hasHeader(parent, adapter, adapterPos))) {
      View header = getHeader(parent, adapter, adapterPos).itemView;
      c.save();
      final int left = child.getLeft();
      final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
      c.translate(left, top);
      header.draw(c);
      c.restore();
    }
  }
}
 
Example 4
Source File: ScrollStateUtil.java    From SimpleProject with MIT License 6 votes vote down vote up
/**
 * RecycleView是否已滑动到顶部
 * @param recyclerView
 * @return
 */
public static boolean recycleViewReachTop(RecyclerView recyclerView) {
	RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
	if (layoutManager == null || layoutManager.getItemCount() == 0) {
		return true;
	}

	View firstChild = recyclerView.getChildAt(0);
	int position = recyclerView.getChildAdapterPosition(firstChild);
	int firstItemTop = firstChild.getTop() - recyclerView.getPaddingTop();

	if (layoutManager instanceof LinearLayoutManager
			&& ((LinearLayoutManager) layoutManager).getOrientation() == LinearLayoutManager.VERTICAL) {
		return position == 0 && firstItemTop == 0;
	} else if (layoutManager instanceof GridLayoutManager) {
		return position < ((GridLayoutManager)layoutManager).getSpanCount() && firstItemTop == 0;
	} else {
		/**
		 * Nothing
		 */
	}

	return false;
}
 
Example 5
Source File: DividerGridItemDecoration.java    From ExRecyclerView with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    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.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicWidth();

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 6
Source File: DividerItemDecoration.java    From DesignSupportDemo with Apache License 2.0 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 7
Source File: SpaceItemDecoration.java    From FoodOrdering with Apache License 2.0 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);
        RecyclerView v = new 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 8
Source File: LuSpacesItemDecoration.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent,LuRecyclerViewAdapter adapter) {
    int count = parent.getChildCount();

    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        final int top = child.getBottom();
        final int bottom = top + verticalSpacing;

        int left = child.getLeft() ;
        int right = child.getRight();

        int position = parent.getChildAdapterPosition(child);

        c.save();

        if (adapter. isHeader(position) || adapter.isFooter(position)) {
            c.drawRect(0, 0, 0, 0, mPaint);
        }else {
            c.drawRect(left, top, right, bottom, mPaint);
        }

        c.restore();
    }
}
 
Example 9
Source File: RBaseItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        LayoutParams params = (LayoutParams) child.getLayoutParams();
        int left = child.getLeft() - params.leftMargin;
        int right = (child.getRight() + params.rightMargin) + this.mDividerHeight;
        int top = child.getBottom() + params.bottomMargin;
        int bottom = top + this.mDividerHeight;
        if (this.mDivider != null) {
            this.mDivider.setBounds(left, top, right, bottom);
            this.mDivider.draw(c);
        }
        if (this.mPaint != null) {
            c.drawRect((float) left, (float) top, (float) right, (float) bottom, this.mPaint);
        }
    }
}
 
Example 10
Source File: DividerItemDecorator.java    From android-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int dividerLeft = parent.getPaddingLeft();
    int dividerRight = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int dividerTop = child.getBottom() + params.bottomMargin;
        int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();

        mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
        mDivider.draw(canvas);
    }
}
 
Example 11
Source File: SupportDividerItemDecoration.java    From fangzhuishushenqi with Apache License 2.0 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 12
Source File: SpaceItemDecoration.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    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 left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 13
Source File: DividerItemDecoration.java    From VCL-Android 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 14
Source File: DividerItemDecoration.java    From WiFiKeyShare with GNU General Public License v3.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 15
Source File: DividerItemDecoration.java    From DesignSupportDemo with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    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 left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 16
Source File: ItemTouchUIUtilImpl.java    From letv with Apache License 2.0 5 votes vote down vote up
private float findMaxElevation(RecyclerView recyclerView, View itemView) {
    int childCount = recyclerView.getChildCount();
    float max = 0.0f;
    for (int i = 0; i < childCount; i++) {
        View child = recyclerView.getChildAt(i);
        if (child != itemView) {
            float elevation = ViewCompat.getElevation(child);
            if (elevation > max) {
                max = elevation;
            }
        }
    }
    return max;
}
 
Example 17
Source File: GridItemDividerDecoration.java    From Simpler with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    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 left = child.getLeft() - params.leftMargin;
        final int right = child.getRight() + params.rightMargin + mDivider.getIntrinsicWidth();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 18
Source File: CircularUtils.java    From CircularViewPager with MIT License 5 votes vote down vote up
/**
 * get the center RecyclerView
 *
 * @param recyclerView
 * @return
 */
public static View getCenterXChild(@NonNull RecyclerView recyclerView) {
    int childCount = recyclerView.getChildCount();
    if (childCount > 0) {
        for (int i = 0; i < childCount; i++) {
            View child = recyclerView.getChildAt(i);
            if (isChildInCenterX(recyclerView, child)) {
                return child;
            }
        }
    }
    return null;
}
 
Example 19
Source File: DividerItemDecoration.java    From DexMovingImageView with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    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 left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 20
Source File: CardViewDecoration.java    From recyclerviewItemDecorations with MIT License 4 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    Rect bounds = new Rect();
    float edgeShadowTop = -mCornerRadius - mShadowSize;

    RecyclerView.LayoutManager lm = parent.getLayoutManager();
    float size16dp = 16f;
    int padding16dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size16dp, parent.getContext().getResources().getDisplayMetrics());

    for (int i = 0; i < parent.getChildCount(); i++) {
        int save = c.save();

        // using decorated values, remove what we set before
        View child = parent.getChildAt(i);
        bounds.set(lm.getDecoratedLeft(child) + padding16dp - (int) mPadding,
                lm.getDecoratedTop(child),
                lm.getDecoratedRight(child) - padding16dp + (int) mPadding,
                lm.getDecoratedBottom(child));

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int position = params.getViewAdapterPosition();
        int viewType = parent.getAdapter().getItemViewType(position);


        if (viewType == HeaderItemTestAdapter.HEADER) {
            bounds.top = (int) (bounds.top + padding16dp - mPadding);

            // LT
            c.translate(bounds.left + mCornerRadius, bounds.top + mCornerRadius);
            c.drawPath(mCornerShadowPath, mCornerShadowPaint);
            c.drawRect(0, edgeShadowTop, bounds.width() - 2 * mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

            // RT
            c.rotate(90f);
            c.translate(0, -bounds.width() + 2 * mCornerRadius);
            c.drawPath(mCornerShadowPath, mCornerShadowPaint);
            c.drawRect(0, edgeShadowTop, bounds.height() - mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

            // LBorder
            c.rotate(180f);
            c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
            c.drawRect(mCornerRadius, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);


        } else {
            if (parent.getAdapter().getItemViewType(position + 1) == HeaderItemTestAdapter.HEADER) {
                bounds.bottom = (int) (bounds.bottom - padding16dp + mPadding);

                // last item before next header
                c.rotate(180f);
                c.translate(-bounds.left - bounds.width() + mCornerRadius, -bounds.top - bounds.height() + mCornerRadius);

                c.drawPath(mCornerShadowPath, mCornerShadowPaint);
                c.drawRect(0, edgeShadowTop, bounds.width() - 2 * mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

                // RT / Right border
                c.rotate(90f);
                c.translate(0, -bounds.width() + 2 * mCornerRadius);
                c.drawPath(mCornerShadowPath, mCornerShadowPaint);
                c.drawRect(0, edgeShadowTop, bounds.height() - mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

                // Left border
                c.rotate(180f);
                c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
                c.drawRect(mCornerRadius, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);
            } else {
                // Right border
                c.translate(bounds.left, bounds.top);
                c.rotate(90f);
                c.translate(0, -bounds.width() + mCornerRadius);
                c.drawRect(0, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);

                // Left border
                c.rotate(180f);
                c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
                c.drawRect(0, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);
            }
        }
        c.restoreToCount(save);
    }
}