类android.support.v7.widget.RecyclerView.LayoutParams源码实例Demo

下面列出了怎么用android.support.v7.widget.RecyclerView.LayoutParams的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FimiX8-RE   文件: RBaseItemDecoration.java
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);
        }
    }
}
 
源代码2 项目: FimiX8-RE   文件: RBaseItemDecoration.java
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);
        }
    }
}
 
源代码3 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
        }
    }
}
 
源代码4 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
        }
    }
}
 
源代码5 项目: vlayout   文件: StaggeredGridLayoutHelper.java
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
        }
    }
}
 
源代码6 项目: vlayout   文件: StaggeredGridLayoutHelper.java
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
        }
    }
}
 
源代码7 项目: letv   文件: LinearLayoutManager.java
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;
}
 
源代码8 项目: UltimateAndroid   文件: TwoWayLayoutManager.java
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;
}
 
源代码9 项目: UltimateAndroid   文件: BaseLayoutManager.java
@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);
    }
}
 
源代码10 项目: Mupdf   文件: LinearLayoutManager.java
/**
 * 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;
}
 
源代码11 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
    }
}
 
源代码12 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
    }
}
 
源代码13 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
    }
}
 
源代码14 项目: FimiX8-RE   文件: DividerGridItemDecoration.java
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);
    }
}
 
源代码15 项目: FimiX8-RE   文件: RecyclerDividerItemDecoration.java
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);
        }
    }
}
 
源代码16 项目: FimiX8-RE   文件: RecyclerDividerItemDecoration.java
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);
        }
    }
}
 
源代码17 项目: vlayout   文件: StaggeredGridLayoutHelper.java
void prependToSpan(View view, OrientationHelperEx helper) {
    LayoutParams lp = getLayoutParams(view);
    mViews.add(0, view);
    mCachedStart = INVALID_LINE;
    if (mViews.size() == 1) {
        mCachedEnd = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize += helper.getDecoratedMeasurement(view);
    }
}
 
源代码18 项目: vlayout   文件: StaggeredGridLayoutHelper.java
void appendToSpan(View view, OrientationHelperEx helper) {
    LayoutParams lp = getLayoutParams(view);
    mViews.add(view);
    mCachedEnd = INVALID_LINE;
    if (mViews.size() == 1) {
        mCachedStart = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize += helper.getDecoratedMeasurement(view);
    }
}
 
源代码19 项目: vlayout   文件: StaggeredGridLayoutHelper.java
void popEnd(OrientationHelperEx helper) {
    final int size = mViews.size();
    View end = mViews.remove(size - 1);
    final LayoutParams lp = getLayoutParams(end);
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize -= helper.getDecoratedMeasurement(end);
    }
    if (size == 1) {
        mCachedStart = INVALID_LINE;
    }
    mCachedEnd = INVALID_LINE;
}
 
源代码20 项目: vlayout   文件: StaggeredGridLayoutHelper.java
void popStart(OrientationHelperEx helper) {
    View start = mViews.remove(0);
    final LayoutParams lp = getLayoutParams(start);
    if (mViews.size() == 0) {
        mCachedEnd = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize -= helper.getDecoratedMeasurement(start);
    }
    mCachedStart = INVALID_LINE;
}
 
源代码21 项目: letv   文件: LinearSmoothScroller.java
public int calculateDyToMakeVisible(View view, int snapPreference) {
    LayoutManager layoutManager = getLayoutManager();
    if (layoutManager == null || !layoutManager.canScrollVertically()) {
        return 0;
    }
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    return calculateDtToFit(layoutManager.getDecoratedTop(view) - params.topMargin, layoutManager.getDecoratedBottom(view) + params.bottomMargin, layoutManager.getPaddingTop(), layoutManager.getHeight() - layoutManager.getPaddingBottom(), snapPreference);
}
 
源代码22 项目: letv   文件: LinearSmoothScroller.java
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);
}
 
源代码23 项目: letv   文件: LinearLayoutManager.java
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;
}
 
源代码24 项目: letv   文件: LinearLayoutManager.java
public void assignPositionFromScrapList(View ignore) {
    View closest = nextViewInLimitedList(ignore);
    if (closest == null) {
        this.mCurrentPosition = -1;
    } else {
        this.mCurrentPosition = ((LayoutParams) closest.getLayoutParams()).getViewLayoutPosition();
    }
}
 
源代码25 项目: letv   文件: LinearLayoutManager.java
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;
}
 
源代码26 项目: basic-adapter   文件: BasicAdapter.java
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);
}
 
源代码27 项目: basic-adapter   文件: BasicAdapter.java
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);
}
 
源代码28 项目: basic-adapter   文件: BasicAdapter.java
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);
}
 
源代码29 项目: basic-adapter   文件: BasicAdapter.java
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);
}
 
源代码30 项目: UltimateAndroid   文件: TwoWayLayoutManager.java
@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);
    }
}
 
 同包方法