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

The following examples show how to use android.support.v7.widget.RecyclerView#getWidth() . 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 frpc-Android with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
        final int left = parent.getPaddingLeft() + margin;
        final int right = parent.getWidth() - parent.getPaddingRight() - margin;

        final int childCount = parent.getChildCount();
        for (int i = 0; i < childCount-corrected; i++) {
            final View child = parent.getChildAt(i);
            final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                    .getLayoutParams();
            final int top = child.getBottom() + params.bottomMargin +
                    Math.round(ViewCompat.getTranslationY(child));
//            final int bottom = top + mDivider.getIntrinsicHeight();
            final int bottom = top + 1;
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }
 
Example 2
Source File: RecycleViewDivider.java    From AndroidHttpCapture 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 3
Source File: DividerItemDecoration.java    From Slice with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent) {
    int left = parent.getPaddingLeft() + leftAddition;
    int right = parent.getWidth() - parent.getPaddingRight() - rightAddition;

    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 4
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 5
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 6
Source File: DividerItemDecoration.java    From baseAdapter 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 7
Source File: SimpleDividerItemDecoration.java    From privacy-friendly-weather with GNU General Public License v3.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 - 1; i++) {
        View child = parent.getChildAt(i);

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

        int top = child.getBottom() + params.bottomMargin;
        Log.d("debug", "Top: " + String.valueOf(top));
        int bottom = top + mDivider.getIntrinsicHeight();
        Log.d("debug", "Bottom: " + String.valueOf(top));

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 8
Source File: DividerItemDecoration.java    From beaconloc with Apache License 2.0 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 + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 9
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 10
Source File: DividerDecoration.java    From recyclerview-playground with MIT License 6 votes vote down vote up
/** Draw dividers underneath each child view */
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 + mInsets;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 11
Source File: PlanDetailActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int childCount = mRecyclerView.getChildCount();
            int width = mRecyclerView.getChildAt(0).getWidth();
            int padding = (mRecyclerView.getWidth() - width) / 2;

            for (int j = 0; j < childCount; j++) {
                View v = recyclerView.getChildAt(j);
                //往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小
                float rate = 0;
                if (v.getLeft() <= padding) {
                    if (v.getLeft() >= padding - v.getWidth()) {
                        rate = (padding - v.getLeft()) * 1f / v.getWidth();
                    } else {
                        rate = 1;
                    }
//                    v.setScaleY(1 - rate * 0.1f);
                    v.setScaleX(1 - rate * 0.1f);

                } else {
                    //往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小
                    if (v.getLeft() <= recyclerView.getWidth() - padding) {
                        rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth();
                    }
//                    v.setScaleY(0.9f + rate * 0.1f);
                    v.setScaleX(0.9f + rate * 0.1f);
                }
            }
        }
 
Example 12
Source File: ViewUtils.java    From MultiView with Apache License 2.0 5 votes vote down vote up
public static boolean isChildInCenterX(RecyclerView recyclerView, View view) {
    int childCount = recyclerView.getChildCount();
    int[] lvLocationOnScreen = new int[2];
    int[] vLocationOnScreen = new int[2];
    recyclerView.getLocationOnScreen(lvLocationOnScreen);
    int middleX = (int) (lvLocationOnScreen[0] + recyclerView.getWidth() * recyclerView.getScaleX() / 2);
    if (childCount > 0) {
        view.getLocationOnScreen(vLocationOnScreen);
        if (vLocationOnScreen[0] <= middleX && vLocationOnScreen[0] + view.getWidth() * view.getScaleX() >= middleX) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: PowerfulStickyDecoration.java    From StickyDecoration with Apache License 2.0 5 votes vote down vote up
/**
 * 通知重新绘制
 * 使用场景:网络图片加载后调用
 *
 * @param recyclerView recyclerView
 * @param realPosition     realPosition
 */
public void notifyRedraw(RecyclerView recyclerView, View viewGroup, int realPosition) {
    viewGroup.setDrawingCacheEnabled(false);
    int firstPositionInGroup = getFirstInGroupWithCash(realPosition);
    mBitmapCache.remove(firstPositionInGroup);
    mHeadViewCache.remove(firstPositionInGroup);
    int left = recyclerView.getPaddingLeft();
    int right = recyclerView.getWidth() - recyclerView.getPaddingRight();
    measureAndLayoutView(viewGroup, left, right);
    mHeadViewCache.put(firstPositionInGroup, viewGroup);
    recyclerView.invalidate();
}
 
Example 14
Source File: SwipeItemTouchListener.java    From Tangram-Android with MIT License 5 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

    mSwipeGestureDector.onTouchEvent(motionEvent);

    if (motionEvent.getAction() == MotionEvent.ACTION_UP ||
            motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {

        final boolean reachActionEdge = swipeType == SWIPING_HOR && (Math.abs(mDistanceX) > (mActionEdge > 0 ?
                mActionEdge : recyclerView.getWidth() / 3));

        boolean reachTabEdge = false;
        if (mSwipeCardRef != null && mSwipeCardRef.get() != null && swipeType == SWIPING_HOR) {
            SwipeCard swipeCard = mSwipeCardRef.get();
            if (swipeCard.getCurrentIndex() == 0 && mDistanceX > 0
                    || (swipeCard.getCurrentIndex() == swipeCard.getTotalPage() - 1) && mDistanceX < 0) {
                reachTabEdge = true;
            }
        }
        int direction = 1;
        if (swipeType == SWIPING_HOR) {
            direction = mDistanceX > 0 ? 1 : -1;
        } else if (swipeType == SWIPING_VER) {
            direction = mDistanceY > 0 ? 1 : -1;
        }
        resetViews(recyclerView, swipeType, reachActionEdge && !reachTabEdge, direction);

    }
}
 
Example 15
Source File: DividerItemDecoration.java    From MicroReader with MIT 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 16
Source File: DragBoardView.java    From DragBoardView with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    int childCount = mRecyclerView.getChildCount();
    int width = mRecyclerView.getChildAt(0).getWidth();
    int padding = (mRecyclerView.getWidth() - width) / 2;

    for (int j = 0; j < childCount; j++) {
        View v = recyclerView.getChildAt(j);
        //往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小
        float rate = 0;
        if (v.getLeft() <= padding) {
            if (v.getLeft() >= padding - v.getWidth()) {
                rate = (padding - v.getLeft()) * 1f / v.getWidth();
            } else {
                rate = 1;
            }
            v.setScaleX(1 - rate * 0.1f);

        } else {
            //往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小
            if (v.getLeft() <= recyclerView.getWidth() - padding) {
                rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth();
            }
            v.setScaleX(0.9f + rate * 0.1f);
        }
    }
}
 
Example 17
Source File: RecyclerDividerItemDecoration.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    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 v = new RecyclerView(parent.getContext());
        int top = child.getBottom() + ((LayoutParams) child.getLayoutParams()).bottomMargin;
        int bottom = top + this.mDividerHeight;
        if (this.mPaint != null) {
            c.drawRect((float) left, (float) top, (float) right, (float) bottom, this.mPaint);
        }
    }
}
 
Example 18
Source File: DividerItemDecoration.java    From EasyAdapter 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);
        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 19
Source File: DividerItemDecoration.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
/**
 * 绘制纵向 item 分割线 这里的parent其实是显示在屏幕显示的这部分
 */
private void drawVertical(Canvas canvas, RecyclerView parent) {
    /**
     当orientation为 Vertical 时,Item的分割线为多条水平的条形
     所以,分割线的Left和Right就比较容易确定
     Left = parent.left = parent.paddingLeft
     right = parent.getWidth() - parent.getPaddingRight
     分割线的 Top 和 Bottom 则需要计算出有多少个Item
     根据Item的位置获取到child的位置坐标
     所以分割线的Top = child的下边的坐标 + child的外边距的距离
     top = child.getBottom() + parms.bottomMargin
     然后根据上边 + 分割线的高度 得到右边的坐标
     bottom = top + mDivider.getIntrinsicHeight()
     为了统一分割线的间隔,故共同使用Height的数值作为间隔的距离
     */
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - 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 (i == 0) {
            if (isMarginTopShow) {
                /**第一个view,可以在顶部加一个margin值*/
                int topF = child.getTop() - layoutParams.topMargin - mDividerHeight;
                int bottomF = child.getTop() - layoutParams.topMargin;
                if (mDivider != null) {
                    mDivider.setBounds(left, topF, right, bottomF);
                    mDivider.draw(canvas);
                    if (isMiddleShow) {
                        mDivider.setBounds(left, top, right, bottom);
                        mDivider.draw(canvas);
                    }
                }
                if (mPaint != null) {
                    canvas.drawRect(left, topF, right, bottomF, 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: HorizontalDividerItemDecoration.java    From AccountBook with GNU General Public License v3.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.left = parent.getPaddingLeft() +
            mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
    bounds.right = parent.getWidth() - parent.getPaddingRight() -
            mMarginProvider.dividerRightMargin(position, parent) + transitionX;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set top and bottom position of divider
        if (isReverseLayout) {
            bounds.bottom = child.getTop() - params.topMargin + transitionY;
            bounds.top = bounds.bottom - dividerSize;
        } else {
            bounds.top = child.getBottom() + params.bottomMargin + transitionY;
            bounds.bottom = bounds.top + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.top = child.getTop() - params.topMargin - halfSize + transitionY;
        } else {
            bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY;
        }
        bounds.bottom = bounds.top;
    }

    if (mPositionInsideItem) {
        if (isReverseLayout) {
            bounds.top += dividerSize;
            bounds.bottom += dividerSize;
        } else {
            bounds.top -= dividerSize;
            bounds.bottom -= dividerSize;
        }
    }

    return bounds;
}