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

The following examples show how to use android.support.v7.widget.RecyclerView#getHeight() . 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 CoordinatorLayoutExample with Apache License 2.0 6 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 2
Source File: RecycleViewScrollHelper.java    From Android with MIT License 6 votes vote down vote up
/**
 * Detect whether to slide to the bottom of the item and callback events
 *
 * @param recyclerView
 * @param lastItemPosition
 * @param itemCount
 * @return
 */
private boolean checkIfScrollToBottom(RecyclerView recyclerView, int lastItemPosition, int itemCount) {
    isScrollBottom = false;
    if (lastItemPosition + 1 == itemCount) {
        if (mIsCheckBottomFullRecycle) {
            int childCount = recyclerView.getChildCount();
            View lastChildView = recyclerView.getChildAt(childCount - 1);
            View firstChildView = recyclerView.getChildAt(0);
            int top = firstChildView.getTop();
            int bottom = lastChildView.getBottom();
            int bottomEdge = recyclerView.getHeight() - recyclerView.getPaddingBottom() + mBottomOffsetFaultTolerance;
            int topEdge = recyclerView.getPaddingTop() + mTopOffsetFaultTolerance;
            if (bottom <= bottomEdge && top < topEdge) {
                mScrollPositionChangedListener.onScrollToBottom();
                isScrollBottom = true;
            } else {
                mScrollPositionChangedListener.onScrollToUnknown(false, true);
            }
        } else {
            mScrollPositionChangedListener.onScrollToBottom();
            isScrollBottom = true;
        }
    }
    return isScrollBottom;
}
 
Example 3
Source File: DividerItemDecoration.java    From CrawlerForReader with Apache License 2.0 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    int childCount = parent.getChildCount();
    childCount = showLastLine ? childCount : childCount - 1;
    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 + 1;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 4
Source File: DividerItemDecoration.java    From NIM_Android_UIKit with MIT License 6 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++) {
        if (!needDrawDecoration(parent, i)) {
            continue;
        }
        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 5
Source File: DividerItemDecoration.java    From MeetMusic with Apache License 2.0 6 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 6
Source File: DividerItemDecoration.java    From rv-adapter-endless with MIT License 6 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 +
                Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 7
Source File: DividerItemDecoration.java    From RecycleClick 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 8
Source File: DividerItemDecoration.java    From Study_Android_Demo 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 9
Source File: RecyclerviewUtils.java    From timecat with Apache License 2.0 5 votes vote down vote up
public static boolean isChildInCenterY(RecyclerView recyclerView, View view) {
    int childCount = recyclerView.getChildCount();
    int[] lvLocationOnScreen = new int[2];
    int[] vLocationOnScreen = new int[2];
    recyclerView.getLocationOnScreen(lvLocationOnScreen);
    int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
    if (childCount > 0) {
        view.getLocationOnScreen(vLocationOnScreen);
        if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: VerticalDividerItemDecoration.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (mPositionInsideItem) {
            bounds.right = child.getRight() + params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.leftMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        if (mPositionInsideItem) {
            bounds.left = child.getRight() + params.leftMargin - dividerSize / 2 + transitionX;
        } else {
            bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
        }
        bounds.right = bounds.left;
    }

    return bounds;
}
 
Example 11
Source File: ViewUtils.java    From RecyclerViewPager with Apache License 2.0 5 votes vote down vote up
public static boolean isChildInCenterY(RecyclerView recyclerView, View view) {
    int childCount = recyclerView.getChildCount();
    int[] lvLocationOnScreen = new int[2];
    int[] vLocationOnScreen = new int[2];
    recyclerView.getLocationOnScreen(lvLocationOnScreen);
    int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
    if (childCount > 0) {
        view.getLocationOnScreen(vLocationOnScreen);
        if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: DividerItemDecoration.java    From nono-android with GNU General Public License v3.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 ZhihuDailyFluxRRD 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 14
Source File: DividerItemDecoration.java    From homage 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);
    }
}
 
Example 15
Source File: TransformItemDecoration.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
  super.onDrawOver(c, parent, state);
  int width = parent.getWidth();
  int height = parent.getHeight();
  for (int i = 0,count=parent.getChildCount(); i < count; i++) {
    updateItem(parent.getChildAt(i),width,height);
  }
}
 
Example 16
Source File: LinePagerIndicatorDecoration.java    From recyclerviewItemDecorations with MIT License 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
  super.onDrawOver(c, parent, state);

  int itemCount = parent.getAdapter().getItemCount();

  // center horizontally, calculate width and subtract half from center
  float totalLength = mIndicatorItemLength * itemCount;
  float paddingBetweenItems = Math.max(0, itemCount - 1) * mIndicatorItemPadding;
  float indicatorTotalWidth = totalLength + paddingBetweenItems;
  float indicatorStartX = (parent.getWidth() - indicatorTotalWidth) / 2F;

  // center vertically in the allotted space
  float indicatorPosY = parent.getHeight() - mIndicatorHeight / 2F;

  drawInactiveIndicators(c, indicatorStartX, indicatorPosY, itemCount);


  // find active page (which should be highlighted)
  LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
  int activePosition = layoutManager.findFirstVisibleItemPosition();
  if (activePosition == RecyclerView.NO_POSITION) {
    return;
  }

  // find offset of active page (if the user is scrolling)
  final View activeChild = layoutManager.findViewByPosition(activePosition);
  int left = activeChild.getLeft();
  int width = activeChild.getWidth();

  // on swipe the active item will be positioned from [-width, 0]
  // interpolate offset for smooth animation
  float progress = mInterpolator.getInterpolation(left * -1 / (float) width);

  drawHighlights(c, indicatorStartX, indicatorPosY, activePosition, progress, itemCount);
}
 
Example 17
Source File: DividerItemDecoration.java    From Hify with MIT License 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 18
Source File: DividerItemDecoration.java    From ZhihuDaily with MIT License 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, (int) (0.06f * bottom + top), right, (int) (0.9 * bottom));
        mDivider.draw(c);
    }
}
 
Example 19
Source File: DividerItemDecoration.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
/**
 * 绘制横向 item 分割线 这里的parent其实是显示在屏幕显示的这部分
 */
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    /**
     当orientation为 Horizontal 时,Item的分割线为多条竖直的条形
     所以,分割线的Top和Bottom就比较容易确定
     top = parent.top = parent.paddingTop
     bottom = parent.getHeight() - parent.getPaddingBottom()
     分割线的 left 和 right 则需要计算出有多少个Item
     根据Item的位置获取到child的位置坐标
     所以分割线的left = child的右边的坐标 + child的外边距的距离
     left = child.right + parms.rightMargin
     然后根据左边 + 分割线的宽度 得到右边的坐标
     right = left + mDivider.getIntrinsicHeight()
     为了统一分割线的间隔,故共同使用Height的数值作为间隔的距离
     */
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    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 left = child.getRight() + layoutParams.rightMargin;
        final int right = left + mDividerHeight;

        /**横向列表*/
        if (i == 0) {
            if (isMarginTopShow) {
                /**第一个view,可以在顶部加一个margin值*/
                int leftF = child.getLeft() - layoutParams.leftMargin - mDividerHeight;
                int rightF = child.getLeft() - layoutParams.leftMargin;
                if (mDivider != null) {
                    mDivider.setBounds(leftF, top, rightF, bottom);
                    mDivider.draw(canvas);
                    if (isMiddleShow) {
                        mDivider.setBounds(left, top, right, bottom);
                        mDivider.draw(canvas);
                    }
                }
                if (mPaint != null) {
                    canvas.drawRect(leftF, top, rightF, bottom, mPaint);
                    if (isMiddleShow) {
                        canvas.drawRect(left, top, right, bottom, mPaint);
                    }
                }
            } else {
                if (isMiddleShow) {
                    if (mDivider != null) {
                        mDivider.setBounds(left, top, right, bottom);
                        mDivider.draw(canvas);
                    }
                    if (mPaint != null) {
                        canvas.drawRect(left, top, right, bottom, mPaint);
                    }
                }
            }
        } else {
            if (isMiddleShow || i >= childSize - 1) {
                /**画竖线,就是往右偏移一个分割线的宽度*/
                if (mDivider != null) {
                    mDivider.setBounds(left, top, right, bottom);
                    mDivider.draw(canvas);
                }
                if (mPaint != null) {
                    canvas.drawRect(left, top, right, bottom, mPaint);
                }
            }
        }


    }

}
 
Example 20
Source File: VerticalDividerItemDecoration.java    From RecyclerView-FlexibleDivider with Apache License 2.0 4 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (isReverseLayout) {
            bounds.right = child.getLeft() - params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.rightMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX;
        } else {
            bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        }
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        if (isReverseLayout) {
            bounds.left += dividerSize;
            bounds.right += dividerSize;
        } else {
            bounds.left -= dividerSize;
            bounds.right -= dividerSize;
        }
    }

    return bounds;
}