android.support.v7.widget.RecyclerView.LayoutParams Java Examples

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: RBaseItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void drawVertical(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 top = child.getTop() - params.topMargin;
        int bottom = child.getBottom() + params.bottomMargin;
        int left = child.getRight() + params.rightMargin;
        int right = left + 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 #2
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the next item from the scrap list.
 * <p>
 * Upon finding a valid VH, sets current item position to VH.itemPosition + mItemDirection
 *
 * @return View if an item in the current position or direction exists if not null.
 */
private View nextViewFromScrapList() {
    final int size = mScrapList.size();
    for (int i = 0; i < size; i++) {
        final View view = mScrapList.get(i).itemView;
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (lp.isItemRemoved()) {
            continue;
        }
        if (mCurrentPosition == lp.getViewLayoutPosition()) {
            assignPositionFromScrapList(view);
            return view;
        }
    }
    return null;
}
 
Example #3
Source File: BaseLayoutManager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(View child, Direction direction) {
    getLaneForChild(mTempLaneInfo, child, direction);

    mLanes.getChildFrame(mChildFrame, getDecoratedMeasuredWidth(child),
            getDecoratedMeasuredHeight(child), mTempLaneInfo, direction);
    final ItemEntry entry = cacheChildFrame(child, mChildFrame);

    layoutDecorated(child, mChildFrame.left, mChildFrame.top, mChildFrame.right,
            mChildFrame.bottom);

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (!lp.isItemRemoved()) {
        pushChildFrame(entry, mChildFrame, mTempLaneInfo.startLane,
                getLaneSpanForChild(child), direction);
    }
}
 
Example #4
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private View makeAndAddView(int position, Direction direction, Recycler recycler) {
    final View child = recycler.getViewForPosition(position);
    final boolean isItemRemoved = ((LayoutParams) child.getLayoutParams()).isItemRemoved();

    if (!isItemRemoved) {
        addView(child, (direction == Direction.END ? -1 : 0));
    }

    setupChild(child, direction);

    if (!isItemRemoved) {
        updateLayoutEdgesFromNewChild(child);
    }

    return child;
}
 
Example #5
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
public View nextViewInLimitedList(View ignore) {
    int size = this.mScrapList.size();
    View closest = null;
    int closestDistance = Integer.MAX_VALUE;
    for (int i = 0; i < size; i++) {
        View view = ((ViewHolder) this.mScrapList.get(i)).itemView;
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!(view == ignore || lp.isItemRemoved())) {
            int distance = (lp.getViewLayoutPosition() - this.mCurrentPosition) * this.mItemDirection;
            if (distance >= 0 && distance < closestDistance) {
                closest = view;
                closestDistance = distance;
                if (distance == 0) {
                    break;
                }
            }
        }
    }
    return closest;
}
 
Example #6
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 6 votes vote down vote up
private void recycleFromEnd(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final int childCount = helper.getChildCount();
    int i;
    for (i = childCount - 1; i >= 0; i--) {
        View child = helper.getChildAt(i);
        if (child != null && orientationHelper.getDecoratedStart(child) > line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int position = lp.getViewPosition();
            Span span = findSpan(position, child, false);
            if (span != null) {
                span.popEnd(orientationHelper);
                helper.removeChildView(child);
                recycler.recycleView(child);
            }
        } else {
            return;// done
        }
    }
}
 
Example #7
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 6 votes vote down vote up
private void recycleFromStart(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    boolean changed = true;
    while (helper.getChildCount() > 0 && changed) {
        View child = helper.getChildAt(0);
        if (child != null && orientationHelper.getDecoratedEnd(child) < line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int position = lp.getViewPosition();
            Span span = findSpan(position, child, true);
            if (span != null) {
                span.popStart(orientationHelper);
                helper.removeChildView(child);
                recycler.recycleView(child);
            } else {
                changed = false;
            }
        } else {
            return;// done
        }
    }
}
 
Example #8
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void drawVertical(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 top = child.getTop() - params.topMargin;
        int bottom = child.getBottom() + params.bottomMargin;
        int left = child.getRight() + params.rightMargin;
        int right = left + 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 #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: DividerGridItemDecoration.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 #11
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
View findReferenceChild(Recycler recycler, State state, int start, int end, int itemCount) {
    ensureLayoutState();
    View invalidMatch = null;
    View outOfBoundsMatch = null;
    int boundsStart = this.mOrientationHelper.getStartAfterPadding();
    int boundsEnd = this.mOrientationHelper.getEndAfterPadding();
    int diff = end > start ? 1 : -1;
    for (int i = start; i != end; i += diff) {
        View childAt = getChildAt(i);
        int position = getPosition(childAt);
        if (position >= 0 && position < itemCount) {
            if (((LayoutParams) childAt.getLayoutParams()).isItemRemoved()) {
                if (invalidMatch == null) {
                    invalidMatch = childAt;
                }
            } else if (this.mOrientationHelper.getDecoratedStart(childAt) < boundsEnd && this.mOrientationHelper.getDecoratedEnd(childAt) >= boundsStart) {
                return childAt;
            } else {
                if (outOfBoundsMatch == null) {
                    outOfBoundsMatch = childAt;
                }
            }
        }
    }
    if (outOfBoundsMatch == null) {
        outOfBoundsMatch = invalidMatch;
    }
    return outOfBoundsMatch;
}
 
Example #12
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 #13
Source File: BasicAdapter.java    From basic-adapter with MIT License 5 votes vote down vote up
private BaseViewHolder onCreateLoadHolder(ViewGroup parent) {
    mLoadLayout = new LinearLayout(parent.getContext());
    mLoadLayout.setOrientation(LinearLayout.VERTICAL);
    mLoadLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    if (mParams.loading != null) {
        mLoadLayout.addView(mParams.loading);
        mParams.loading.setVisibility(View.GONE);
    }
    if (mParams.loaded != null) {
        mLoadLayout.addView(mParams.loaded);
        mParams.loaded.setVisibility(View.GONE);
    }
    return new BaseViewHolder(mLoadLayout);
}
 
Example #14
Source File: BasicAdapter.java    From basic-adapter with MIT License 5 votes vote down vote up
private BaseViewHolder onCreateEmptyHolder(ViewGroup parent) {
    mEmptyLayout = (LinearLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_container, parent, false);
    if (mParams.empty != null) {
        mEmptyLayout.addView(mParams.empty, 0, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    }
    return new BaseViewHolder(mEmptyLayout);
}
 
Example #15
Source File: BasicAdapter.java    From basic-adapter with MIT License 5 votes vote down vote up
private BaseViewHolder onCreateFooterHolder(ViewGroup parent) {
    mFooterLayout = new LinearLayout(parent.getContext());
    mFooterLayout.setOrientation(LinearLayout.VERTICAL);
    mFooterLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    for (View footer : mParams.footers) {
        mFooterLayout.addView(footer);
    }
    return new BaseViewHolder(mFooterLayout);
}
 
Example #16
Source File: BasicAdapter.java    From basic-adapter with MIT License 5 votes vote down vote up
private BaseViewHolder onCreateHeaderHolder(ViewGroup parent) {
    mHeaderLayout = new LinearLayout(parent.getContext());
    mHeaderLayout.setOrientation(LinearLayout.VERTICAL);
    mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    for (View header : mParams.headers) {
        mHeaderLayout.addView(header);
    }
    return new BaseViewHolder(mHeaderLayout);
}
 
Example #17
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawVertical(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.getRight() + params.rightMargin;
        int right = left + this.mDivider.getIntrinsicWidth();
        this.mDivider.setBounds(left, child.getTop() - params.topMargin, right, child.getBottom() + params.bottomMargin);
        this.mDivider.draw(c);
    }
}
 
Example #18
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public LayoutParams generateDefaultLayoutParams() {
    if (mIsVertical) {
        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    } else {
        return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    }
}
 
Example #19
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 5 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 top = child.getBottom() + params.bottomMargin;
        this.mDivider.setBounds(child.getLeft() - params.leftMargin, top, (child.getRight() + params.rightMargin) + this.mDivider.getIntrinsicWidth(), top + this.mDivider.getIntrinsicHeight());
        this.mDivider.draw(c);
    }
}
 
Example #20
Source File: BaseLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkLayoutParams(LayoutParams lp) {
    if (isVertical()) {
        return (lp.width == LayoutParams.MATCH_PARENT);
    } else {
        return (lp.height == LayoutParams.MATCH_PARENT);
    }
}
 
Example #21
Source File: BaseLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public LayoutParams generateDefaultLayoutParams() {
    if (isVertical()) {
        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    } else {
        return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    }
}
 
Example #22
Source File: BaseLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
    final LayoutParams lanedLp = new LayoutParams((MarginLayoutParams) lp);
    if (isVertical()) {
        lanedLp.width = LayoutParams.MATCH_PARENT;
        lanedLp.height = lp.height;
    } else {
        lanedLp.width = lp.width;
        lanedLp.height = LayoutParams.MATCH_PARENT;
    }

    return lanedLp;
}
 
Example #23
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
View findReferenceChild(RecyclerView.Recycler recycler, RecyclerView.State state,
                        int start, int end, int itemCount) {
    ensureLayoutState();
    View invalidMatch = null;
    View outOfBoundsMatch = null;
    final int boundsStart = mOrientationHelper.getStartAfterPadding();
    final int boundsEnd = mOrientationHelper.getEndAfterPadding();
    final int diff = end > start ? 1 : -1;
    for (int i = start; i != end; i += diff) {
        final View view = getChildAt(i);
        final int position = getPosition(view);
        if (position >= 0 && position < itemCount) {
            if (((LayoutParams) view.getLayoutParams()).isItemRemoved()) {
                if (invalidMatch == null) {
                    invalidMatch = view; // removed item, least preferred
                }
            } else if (mOrientationHelper.getDecoratedStart(view) >= boundsEnd ||
                    mOrientationHelper.getDecoratedEnd(view) < boundsStart) {
                if (outOfBoundsMatch == null) {
                    outOfBoundsMatch = view; // item is not visible, less preferred
                }
            } else {
                return view;
            }
        }
    }
    return outOfBoundsMatch != null ? outOfBoundsMatch : invalidMatch;
}
 
Example #24
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
public void assignPositionFromScrapList(View ignore) {
    final View closest = nextViewInLimitedList(ignore);
    if (closest == null) {
        mCurrentPosition = NO_POSITION;
    } else {
        mCurrentPosition = ((LayoutParams) closest.getLayoutParams())
                .getViewLayoutPosition();
    }
}
 
Example #25
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
public View nextViewInLimitedList(View ignore) {
    int size = mScrapList.size();
    View closest = null;
    int closestDistance = Integer.MAX_VALUE;
    if (DEBUG && mIsPreLayout) {
        throw new IllegalStateException("Scrap list cannot be used in pre layout");
    }
    for (int i = 0; i < size; i++) {
        View view = mScrapList.get(i).itemView;
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (view == ignore || lp.isItemRemoved()) {
            continue;
        }
        final int distance = (lp.getViewLayoutPosition() - mCurrentPosition) *
                mItemDirection;
        if (distance < 0) {
            continue; // item is not in current direction
        }
        if (distance < closestDistance) {
            closest = view;
            closestDistance = distance;
            if (distance == 0) {
                break;
            }
        }
    }
    return closest;
}
 
Example #26
Source File: RecyclerDividerItemDecoration.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        View child = parent.getChildAt(i);
        int left = child.getRight() + ((LayoutParams) child.getLayoutParams()).rightMargin;
        int right = left + this.mDividerHeight;
        if (this.mPaint != null) {
            c.drawRect((float) left, (float) top, (float) right, (float) bottom, this.mPaint);
        }
    }
}
 
Example #27
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public void assignPositionFromScrapList(View ignore) {
    View closest = nextViewInLimitedList(ignore);
    if (closest == null) {
        this.mCurrentPosition = -1;
    } else {
        this.mCurrentPosition = ((LayoutParams) closest.getLayoutParams()).getViewLayoutPosition();
    }
}
 
Example #28
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private View nextViewFromScrapList() {
    int size = this.mScrapList.size();
    for (int i = 0; i < size; i++) {
        View view = ((ViewHolder) this.mScrapList.get(i)).itemView;
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!lp.isItemRemoved() && this.mCurrentPosition == lp.getViewLayoutPosition()) {
            assignPositionFromScrapList(view);
            return view;
        }
    }
    return null;
}
 
Example #29
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawVertical(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.getRight() + params.rightMargin;
        int right = left + this.mDivider.getIntrinsicWidth();
        this.mDivider.setBounds(left, child.getTop() - params.topMargin, right, child.getBottom() + params.bottomMargin);
        this.mDivider.draw(c);
    }
}
 
Example #30
Source File: LinearSmoothScroller.java    From letv with Apache License 2.0 5 votes vote down vote up
public int calculateDxToMakeVisible(View view, int snapPreference) {
    LayoutManager layoutManager = getLayoutManager();
    if (layoutManager == null || !layoutManager.canScrollHorizontally()) {
        return 0;
    }
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    return calculateDtToFit(layoutManager.getDecoratedLeft(view) - params.leftMargin, layoutManager.getDecoratedRight(view) + params.rightMargin, layoutManager.getPaddingLeft(), layoutManager.getWidth() - layoutManager.getPaddingRight(), snapPreference);
}