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

The following examples show how to use android.support.v7.widget.RecyclerView#getMeasuredWidth() . 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: RecycleViewDivider.java    From VideoPlayer with Apache License 2.0 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 2
Source File: KyRecyclerViewDivider.java    From BitkyShop 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 3
Source File: RecycleViewDivider.java    From httplite with Apache License 2.0 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 4
Source File: RecycleViewDivider.java    From LLApp with Apache License 2.0 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 5
Source File: RecycleViewItemLine.java    From YCRefreshView with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制横向 item 分割线
 */
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getMeasuredWidth() - parent.getPaddingRight();
    RefreshLogUtils.d("小杨逗比左右的间距分别是" + left + "----"+right);
    //获取的当前显示的view的数量,并不会获取不显示的view的数量。
    //假如recyclerView里共有30条数据,而当前屏幕内显示的只有5条,这paren.getChildCount的值是5,不是30。
    final int childSize = parent.getChildCount();
    for (int i = 0; i < childSize; i++) {
        //获取索引i处的控件view
        final View child = parent.getChildAt(i);
        //拿到layoutParams属性
        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);
        }
        //使用画笔paint进行绘制
        if (mPaint != null) {
            canvas.drawRect(left, top, right, bottom, mPaint);
        }
    }
}
 
Example 6
Source File: RecycleViewDivider.java    From Bailan with Apache License 2.0 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 7
Source File: RecycleViewDivider.java    From SoloPi with Apache License 2.0 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: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void fireScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
  int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
  int contentHeight = recyclerView.computeVerticalScrollRange();

  Map<String, Object> event = new HashMap<>(2);
  Map<String, Object> contentSize = new HashMap<>(2);
  Map<String, Object> contentOffset = new HashMap<>(2);

  contentSize.put(Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(contentWidth, getInstance().getInstanceViewPortWidth()));
  contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getInstanceViewPortWidth()));

  contentOffset.put(Constants.Name.X, - WXViewUtils.getWebPxByWidth(offsetX, getInstance().getInstanceViewPortWidth()));
  contentOffset.put(Constants.Name.Y, - WXViewUtils.getWebPxByWidth(offsetY, getInstance().getInstanceViewPortWidth()));
  event.put(Constants.Name.CONTENT_SIZE, contentSize);
  event.put(Constants.Name.CONTENT_OFFSET, contentOffset);

  fireEvent(Constants.Event.SCROLL, event);
}
 
Example 9
Source File: RecycleViewDivider.java    From Bailan with Apache License 2.0 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 10
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 11
Source File: RecycleViewDivider.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 12
Source File: RecycleViewDivider.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 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 13
Source File: GroupItemDecoration.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制分组Group
 *
 * @param c      Canvas
 * @param parent RecyclerView
 */
protected void onDrawGroup(Canvas c, RecyclerView parent) {
    int paddingLeft = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    int top, bottom;
    int count = parent.getChildCount();
    for (int i = 0; i < parent.getChildCount(); i++) {
        View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int key = params.getViewLayoutPosition();
        if (mGroup.containsKey(key)) {
            top = child.getTop() - params.topMargin - mGroupHeight;
            bottom = top + mGroupHeight;
            c.drawRect(paddingLeft, top, right, bottom, mBackgroundPaint);
            String group = mGroup.get(params.getViewLayoutPosition()).toString();
            float x;
            float y = top + mTextBaseLine;
            if (isCenter) {
                x = parent.getMeasuredWidth() / 2 - getTextX(group);
            } else {
                x = mPaddingLeft;
            }
            c.drawText(group, x, y, mTextPaint);
        }
    }
}
 
Example 14
Source File: RecycleViewDivider.java    From imsdk-android 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 15
Source File: ToDayView.java    From ToDay with MIT License 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, State state) {
    int top, left = 0, right = parent.getMeasuredWidth();
    for (int i = 0; i < parent.getChildCount(); i++) {
        top = parent.getChildAt(i).getTop() - mSize / 2;
        c.drawLine(left, top, right, top, mPaint);
    }
}
 
Example 16
Source File: CommonRecyclerAdapter.java    From QPM with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    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 + dividerHeight;
        canvas.drawRect(left, top, right, bottom, mPaint);
    }
}
 
Example 17
Source File: TimelineScrollListener.java    From datepicker-timeline with MIT License 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    int scrollOffset = recyclerView.computeHorizontalScrollOffset();
    int scrollOffsetCenter = scrollOffset + (recyclerView.getMeasuredWidth() / 2);
    int centerPosition = scrollOffsetCenter / timelineItemWidth;

    if (!(scrollOffsetCenter >= yearStartOffset && scrollOffsetCenter <= yearEndOffset)) {
        calendar.set(timelineView.getStartYear(), timelineView.getStartMonth(), timelineView.getStartDay());
        int startDay = calendar.get(Calendar.DAY_OF_YEAR);
        calendar.add(Calendar.DAY_OF_YEAR, centerPosition);

        year = calendar.get(Calendar.YEAR);
        int yearDayCount = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);

        if (year != timelineView.getStartYear()) {
            int yearDay = calendar.get(Calendar.DAY_OF_YEAR);
            yearStartOffset = scrollOffsetCenter
                    - yearDay * timelineItemWidth
                    - scrollOffsetCenter % timelineItemWidth;
            monthCount = 12;
        } else {
            yearStartOffset = 0;
            monthCount = 12 - timelineView.getStartMonth();
            yearDayCount -= startDay;
        }

        yearEndOffset = yearStartOffset + yearDayCount * timelineItemWidth;
    }

    Log.v("TimeScrollListener", "yearStartOffset: " + yearStartOffset + ", " + "yearEndOffset: " + yearEndOffset + ", "
            + "scrollOffsetCenter: " + scrollOffsetCenter);
    float progress = (float) (scrollOffsetCenter - yearStartOffset) / (yearEndOffset - yearStartOffset);
    int yearOffset = (int) ((1 - progress) * (monthCount * monthView.getItemWidth()));
    Log.v("TimeScrollListener", "progress: " + progress + ", monthOffset: " + yearOffset);
    monthView.scrollToYearPosition(year, yearOffset);
}
 
Example 18
Source File: DividerItemDecoration.java    From easyweather with MIT License 5 votes vote down vote up
/**
 * 绘制纵向 item 分割线
 * @param canvas 画布
 * @param parent 父布局
 */
private void drawVertical(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 + mItemSize ;
        canvas.drawRect(left,top,right,bottom,mPaint);
    }
}
 
Example 19
Source File: RecycleViewDivider.java    From UGank with GNU General Public License v3.0 5 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);
        }
    }
}
 
Example 20
Source File: GroupItemDecoration.java    From timecat with Apache License 2.0 4 votes vote down vote up
/**
 * 绘制悬浮组
 *
 * @param c      Canvas
 * @param parent RecyclerView
 */
protected void onDrawOverGroup(Canvas c, RecyclerView parent) {
    int firstVisiblePosition = ((LinearLayoutManager) parent.getLayoutManager()).findFirstVisibleItemPosition();
    if (firstVisiblePosition == RecyclerView.NO_POSITION) {
        return;
    }
    Group group = getCroup(firstVisiblePosition);
    if (group == null)
        return;
    String groupTitle = group.toString();
    if (TextUtils.isEmpty(groupTitle)) {
        return;
    }
    boolean isRestore = false;
    Group nextGroup = getCroup(firstVisiblePosition + 1);
    if (nextGroup != null && !group.equals(nextGroup)) {
        //说明是当前组最后一个元素,但不一定碰撞了
        View child = parent.findViewHolderForAdapterPosition(firstVisiblePosition).itemView;
        if (child.getTop() + child.getMeasuredHeight() < mGroupHeight) {
            //进一步检测碰撞
            c.save();//保存画布当前的状态
            isRestore = true;
            c.translate(0, child.getTop() + child.getMeasuredHeight() - mGroupHeight);
        }
    }
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    int top = parent.getPaddingTop();
    int bottom = top + mGroupHeight;
    c.drawRect(left, top, right, bottom, mBackgroundPaint);
    float x;
    float y = top + mTextBaseLine;
    if (isCenter) {
        x = parent.getMeasuredWidth() / 2 - getTextX(groupTitle);
    } else {
        x = mPaddingLeft;
    }
    c.drawText(groupTitle, x, y, mTextPaint);
    if (isRestore) {
        //还原画布为初始状态
        c.restore();
    }
}