Java Code Examples for android.support.v7.widget.RecyclerView#LayoutParams

The following examples show how to use android.support.v7.widget.RecyclerView#LayoutParams . 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: DividerGridItemDecoration.java    From KUtils-master with Apache License 2.0 6 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.getRight() + params.rightMargin;
        final int right = left + mDivideHeight;
        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 2
Source File: SupportDividerItemDecoration.java    From BookReader 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 3
Source File: KyRecyclerViewDivider.java    From BitkyShop with MIT License 6 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
  final int top = parent.getPaddingTop();
  final int bottom = parent.getMeasuredHeight() - 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 (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: DividerItemDecoration.java    From NIM_Android_UIKit 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++) {
        if (!needDrawDecoration(parent, i)) {
            continue;
        }
        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 5
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 6
Source File: DividerItemDecoration.java    From Xrv with Apache License 2.0 6 votes vote down vote up
/**
 * Adds dividers to a RecyclerView with a LinearLayoutManager or its
 * subclass oriented vertically.
 *
 * @param canvas The {@link Canvas} onto which vertical dividers will be
 *               drawn
 * @param parent The RecyclerView onto which vertical dividers are being
 *               added
 */
private void drawVerticalDividers(Canvas canvas, RecyclerView parent) {
    int parentLeft = parent.getPaddingLeft();
    int parentRight = 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 parentTop = child.getBottom() + params.bottomMargin;
        int parentBottom = parentTop + mDivider.getIntrinsicHeight();

        mDivider.setBounds(parentLeft, parentTop, parentRight, parentBottom);
        mDivider.draw(canvas);
    }
}
 
Example 7
Source File: ExStaggeredGridLayoutManager.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
        int heightSpec, int[] measuredDimension) {

    // 挨个遍历所有item
    if (position < getItemCount()) {
        try {
            View view = recycler.getViewForPosition(position);//fix 动态添加时报IndexOutOfBoundsException

            if (view != null) {
                RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) view.getLayoutParams();
                int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, getPaddingLeft() + getPaddingRight(), lp.width);
                int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom(), lp.height);
                // 子view进行测量,然后可以通过getMeasuredWidth()获得测量的宽,高类似
                view.measure(childWidthSpec, childHeightSpec);
                // 将item的宽高放入数组中
                measuredDimension[0] = view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
                measuredDimension[1] = view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
                recycler.recycleView(view);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 8
Source File: DividerItemDecoration.java    From AndroidDemo with MIT License 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent)
{
	final int left = parent.getPaddingLeft() + DIVIDER_PADING_LEFT;
	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 9
Source File: SimpleDividerItemDecoration.java    From android-test-demo with MIT License 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 10
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 11
Source File: SuggestionItemDecorator.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int visibleCount = parent.getChildCount();
    int count = state.getItemCount();
    RecyclerView.Adapter adapter = parent.getAdapter();
    int adapterCount = adapter != null ? adapter.getItemCount() : 0;

    for (int i = 0; i < visibleCount; i++) {
        View view = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(view);
        float translationX = ViewCompat.getTranslationX(view);
        float translationY = ViewCompat.getTranslationY(view);
        float alpha = ViewCompat.getAlpha(view);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();

        int shadows = LEFT|RIGHT;
        if(position == count - 1 && adapterCount != 0) shadows|=BOTTOM;

        drawable.setAlpha((int) (255*alpha));
        drawable.setShadow(shadows);
        drawable.setBounds(0, 0, parent.getWidth(), view.getHeight());
        int saved = canvas.save();
            canvas.translate(parent.getPaddingLeft() + translationX,
                            view.getTop() + params.topMargin + translationY);
            drawable.draw(canvas);
        canvas.restoreToCount(saved);
    }
}
 
Example 12
Source File: AbstractSnapperLLM.java    From MultiView with Apache License 2.0 5 votes vote down vote up
@Override
public void addView(View child, int index) {
    RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
    if (showOneItemOnly) {
        if (canScrollHorizontally()) {
            lp.width = getWidth();
            if (lp.height != -2) {
                lp.height = getHeight();
            }
        } else {
            lp.height = getHeight();
            if (lp.width != -2) {
                lp.width = getWidth();
            }
        }
    } else {
        if (lp instanceof LayoutParams) {
            lp.width = ((LayoutParams) lp).origWidth;
            lp.height = ((LayoutParams) lp).origHeight;
        } else if (lp instanceof ScalableGridLayoutManager.LayoutParams) {
            lp.width = ((ScalableGridLayoutManager.LayoutParams) lp).getOrigWidth();
            lp.height = ((ScalableGridLayoutManager.LayoutParams) lp).getOrigHeight();
        }

    }
    super.addView(child, index);
}
 
Example 13
Source File: Y_DividerItemDecoration.java    From Y_DividerItemDecoration with Apache License 2.0 5 votes vote down vote up
private void drawChildRightVertical(View child, Canvas c, RecyclerView parent, @ColorInt int color, int lineWidthPx, int startPaddingPx, int endPaddingPx) {

        int topPadding = 0;
        int bottomPadding = 0;

        if (startPaddingPx <= 0) {
            //padding<0当作==0处理
            //上下左右默认分割线的两头都出头一个分割线的宽度,避免十字交叉的时候,交叉点是空白
            topPadding = -lineWidthPx;
        } else {
            topPadding = startPaddingPx;
        }
        if (endPaddingPx <= 0) {
            bottomPadding = lineWidthPx;
        } else {
            bottomPadding = -endPaddingPx;
        }

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        int top = child.getTop() - params.topMargin + topPadding;
        int bottom = child.getBottom() + params.bottomMargin + bottomPadding;
        int left = child.getRight() + params.rightMargin;
        int right = left + lineWidthPx;
        mPaint.setColor(color);

        c.drawRect(left, top, right, bottom, mPaint);

    }
 
Example 14
Source File: ValuePicker.java    From NumberPicker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ValuePickerAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == VIEW_TYPE_ITEM) {
        TextView number = getTextView(mContext, mTextSize, mTextSizeSelected);
        return new ItemHolder(number);
    } else {
        View paddingView = new View(mContext);
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(dp2px(mContext, 1), (int) mItemSmallHeight);
        paddingView.setLayoutParams(layoutParams);
        return new PaddingHolder(paddingView);
    }
}
 
Example 15
Source File: HorizontalDividerItemDecoration.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.left = parent.getPaddingLeft() +
            mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
    bounds.right = parent.getWidth() - parent.getPaddingRight() -
            mMarginProvider.dividerRightMargin(position, parent) + transitionX;

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

    return bounds;
}
 
Example 16
Source File: DividerItemDecoration.java    From RxJoke 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: GridLayoutManager.java    From TvRecyclerView with Apache License 2.0 4 votes vote down vote up
private int getDecoratedMeasurementHorizontal(View view) {
    final RecyclerView.MarginLayoutParams params = (RecyclerView.LayoutParams)
            view.getLayoutParams();
    return getDecoratedMeasuredWidth(view) + params.leftMargin
            + params.rightMargin;
}
 
Example 18
Source File: WrapAdapter.java    From RecyclerViewTools with Apache License 2.0 4 votes vote down vote up
private void setDefaultLayoutParams(View v) {
   if (v.getLayoutParams() == null) {
      RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
      v.setLayoutParams(lp);
   }
}
 
Example 19
Source File: VegaLayoutManager.java    From GankGirl with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
    return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
 
Example 20
Source File: AutoRecyclerView.java    From AutoLayout-Android with Apache License 2.0 4 votes vote down vote up
public GridLayoutParams(RecyclerView.LayoutParams source) {
    super(source);
}