Search in sources :

Example 26 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class OnePlusNLayoutHelperEx method handleFive.

private int handleFive(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper, boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    int mainConsumed = 0;
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final View child1 = mChildrenViews[0];
    final VirtualLayoutManager.LayoutParams lp1 = (VirtualLayoutManager.LayoutParams) child1.getLayoutParams();
    final View child2 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[1];
    final VirtualLayoutManager.LayoutParams lp2 = (VirtualLayoutManager.LayoutParams) child2.getLayoutParams();
    final View child3 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[2];
    final VirtualLayoutManager.LayoutParams lp3 = (VirtualLayoutManager.LayoutParams) child3.getLayoutParams();
    final View child4 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[3];
    final VirtualLayoutManager.LayoutParams lp4 = (VirtualLayoutManager.LayoutParams) child4.getLayoutParams();
    final View child5 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[4];
    final VirtualLayoutManager.LayoutParams lp5 = (VirtualLayoutManager.LayoutParams) child5.getLayoutParams();
    final float weight1 = getViewMainWeight(0);
    final float weight2 = getViewMainWeight(1);
    final float weight3 = getViewMainWeight(2);
    final float weight4 = getViewMainWeight(3);
    final float weight5 = getViewMainWeight(4);
    if (layoutInVertical) {
        lp2.topMargin = lp1.topMargin;
        lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
        lp3.leftMargin = lp2.leftMargin;
        lp4.rightMargin = lp2.rightMargin;
        lp5.rightMargin = lp3.rightMargin;
        if (!Float.isNaN(mAspectRatio)) {
            lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
        }
        int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
        int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
        int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
        int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5f);
        int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
        int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
        helper.measureChildWithMargins(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
        int height1 = child1.getMeasuredHeight();
        int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
        int height3 = (height1 - lp2.bottomMargin - lp3.topMargin) - height2;
        helper.measureChildWithMargins(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
        mainConsumed = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, height2 + lp2.topMargin + lp2.bottomMargin + Math.max(height3 + lp3.topMargin + lp3.bottomMargin, height3 + lp4.topMargin + lp4.bottomMargin)) + getVerticalMargin() + getVerticalPadding();
        calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
        int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
        layoutChildWithMargin(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
        int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
        layoutChildWithMargin(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
        int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
        layoutChildWithMargin(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
        int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
        layoutChildWithMargin(child4, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right4, mAreaRect.bottom, helper);
        layoutChildWithMargin(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right4 + orientationHelper.getDecoratedMeasurementInOther(child5), mAreaRect.bottom, helper);
    } else {
    // TODO: horizontal support
    }
    handleStateOnResult(result, mChildrenViews);
    return mainConsumed;
}
Also used : OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 27 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class OnePlusNLayoutHelperEx method handSeven.

private int handSeven(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper, boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    int mainConsumed = 0;
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final View child1 = mChildrenViews[0];
    final VirtualLayoutManager.LayoutParams lp1 = (VirtualLayoutManager.LayoutParams) child1.getLayoutParams();
    final View child2 = helper.getReverseLayout() ? mChildrenViews[6] : mChildrenViews[1];
    final VirtualLayoutManager.LayoutParams lp2 = (VirtualLayoutManager.LayoutParams) child2.getLayoutParams();
    final View child3 = helper.getReverseLayout() ? mChildrenViews[5] : mChildrenViews[2];
    final VirtualLayoutManager.LayoutParams lp3 = (VirtualLayoutManager.LayoutParams) child3.getLayoutParams();
    final View child4 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[3];
    final VirtualLayoutManager.LayoutParams lp4 = (VirtualLayoutManager.LayoutParams) child4.getLayoutParams();
    final View child5 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[4];
    final VirtualLayoutManager.LayoutParams lp5 = (VirtualLayoutManager.LayoutParams) child5.getLayoutParams();
    final View child6 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[5];
    final VirtualLayoutManager.LayoutParams lp6 = (VirtualLayoutManager.LayoutParams) child6.getLayoutParams();
    final View child7 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[6];
    final VirtualLayoutManager.LayoutParams lp7 = (VirtualLayoutManager.LayoutParams) child7.getLayoutParams();
    final float weight1 = getViewMainWeight(0);
    final float weight2 = getViewMainWeight(1);
    final float weight3 = getViewMainWeight(2);
    final float weight4 = getViewMainWeight(3);
    final float weight5 = getViewMainWeight(4);
    final float weight6 = getViewMainWeight(5);
    final float weight7 = getViewMainWeight(6);
    if (layoutInVertical) {
        if (!Float.isNaN(mAspectRatio)) {
            lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
        }
        int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
        int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
        int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
        int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5);
        int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
        int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
        int width6 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight6 / 100 + 0.5f);
        int width7 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight7 / 100 + 0.5f);
        helper.measureChildWithMargins(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
        int height1 = child1.getMeasuredHeight();
        int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 3.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
        helper.measureChildWithMargins(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child6, MeasureSpec.makeMeasureSpec(width6 + lp6.leftMargin + lp6.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp6.topMargin + lp6.bottomMargin, MeasureSpec.EXACTLY));
        helper.measureChildWithMargins(child7, MeasureSpec.makeMeasureSpec(width7 + lp7.leftMargin + lp7.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp7.topMargin + lp7.bottomMargin, MeasureSpec.EXACTLY));
        int maxRightHeight = Math.max(height2 + lp2.topMargin + lp2.bottomMargin, height2 + lp3.topMargin + lp3.bottomMargin) + Math.max(height2 + lp4.topMargin + lp4.bottomMargin, height2 + lp5.topMargin + lp5.bottomMargin) + Math.max(height2 + lp6.topMargin + lp6.bottomMargin, height2 + lp7.topMargin + lp7.bottomMargin);
        int maxHeight = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, maxRightHeight);
        mainConsumed = maxHeight + getVerticalMargin() + getVerticalPadding();
        calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
        int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
        layoutChildWithMargin(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
        int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
        layoutChildWithMargin(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
        int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
        layoutChildWithMargin(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
        int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
        layoutChildWithMargin(child4, right1, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), helper);
        int right5 = right4 + orientationHelper.getDecoratedMeasurementInOther(child5);
        layoutChildWithMargin(child5, right4, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right5, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), helper);
        int right6 = right1 + orientationHelper.getDecoratedMeasurementInOther(child6);
        layoutChildWithMargin(child6, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), right6, mAreaRect.bottom, helper);
        layoutChildWithMargin(child7, right6, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), right6 + orientationHelper.getDecoratedMeasurementInOther(child7), mAreaRect.bottom, helper);
    } else {
    // TODO: horizontal support
    }
    handleStateOnResult(result, mChildrenViews);
    return mainConsumed;
}
Also used : OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 28 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class RangeStyle method adjustLayout.

public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) {
    if (!isChildrenEmpty()) {
        for (Map.Entry<Range<Integer>, T> entry : mChildren.entrySet()) {
            RangeStyle rangeStyle = entry.getValue();
            rangeStyle.adjustLayout(startPosition, endPosition, helper);
        }
    }
    if (requireLayoutView()) {
        View refer = null;
        Rect tempRect = new Rect();
        final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
        for (int i = 0; i < helper.getChildCount(); i++) {
            refer = helper.getChildAt(i);
            int anchorPos = helper.getPosition(refer);
            if (getRange().contains(anchorPos)) {
                if (refer.getVisibility() == View.GONE) {
                    tempRect.setEmpty();
                } else {
                    final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) refer.getLayoutParams();
                    if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) {
                        tempRect.union(helper.getDecoratedLeft(refer) - params.leftMargin, orientationHelper.getDecoratedStart(refer), helper.getDecoratedRight(refer) + params.rightMargin, orientationHelper.getDecoratedEnd(refer));
                    } else {
                        tempRect.union(orientationHelper.getDecoratedStart(refer), helper.getDecoratedTop(refer) - params.topMargin, orientationHelper.getDecoratedEnd(refer), helper.getDecoratedBottom(refer) + params.bottomMargin);
                    }
                }
            }
        }
        if (!tempRect.isEmpty()) {
            mLayoutRegion.set(tempRect.left - mPaddingLeft, tempRect.top - mPaddingTop, tempRect.right + mPaddingRight, tempRect.bottom + mPaddingBottom);
        } else {
            mLayoutRegion.setEmpty();
        }
        if (mLayoutView != null) {
            mLayoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom);
        }
    }
}
Also used : Rect(android.graphics.Rect) OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) Range(com.alibaba.android.vlayout.Range) SimpleArrayMap(android.support.v4.util.SimpleArrayMap) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 29 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class ColumnLayoutHelper method layoutViews.

@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, VirtualLayoutManager.LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
    // reach the end of this layout
    if (isOutOfRange(layoutState.getCurrentPosition())) {
        return;
    }
    final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final int itemCount = getItemCount();
    if (mViews == null || mViews.length != itemCount) {
        mViews = new View[itemCount];
    }
    if (mEqViews == null || mEqViews.length != itemCount) {
        mEqViews = new View[itemCount];
    } else {
        Arrays.fill(mEqViews, null);
    }
    final int count = getAllChildren(mViews, recycler, layoutState, result, helper);
    if (layoutInVertical) {
        // TODO: only handle vertical layout now
        int maxVMargin = 0;
        int lastHMargin = 0;
        int totalMargin = 0;
        for (int i = 0; i < count; i++) {
            View view = mViews[i];
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams instanceof RecyclerView.LayoutParams) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) layoutParams;
                params.leftMargin = Math.max(lastHMargin, params.leftMargin);
                totalMargin += params.leftMargin;
                if (i != count - 1) {
                    // not last item
                    lastHMargin = params.rightMargin;
                    params.rightMargin = 0;
                } else {
                    totalMargin += params.rightMargin;
                }
                maxVMargin = Math.max(maxVMargin, params.topMargin + params.bottomMargin);
            }
        }
        final int totalWidth = helper.getContentWidth() - helper.getPaddingLeft() - helper.getPaddingRight() - getHorizontalMargin() - getHorizontalPadding();
        final int availableWidth = totalWidth - totalMargin;
        int usedWidth = 0;
        int minHeight = Integer.MAX_VALUE;
        int uniformHeight = -1;
        if (!Float.isNaN(mAspectRatio)) {
            uniformHeight = (int) (totalWidth / mAspectRatio + 0.5f);
        }
        int eqSize = 0;
        for (int i = 0; i < count; i++) {
            View view = mViews[i];
            VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) view.getLayoutParams();
            int heightSpec = helper.getChildMeasureSpec(helper.getContentHeight() - helper.getPaddingTop() - helper.getPaddingBottom(), uniformHeight > 0 ? uniformHeight : params.height, true);
            if (mWeights != null && i < mWeights.length && !Float.isNaN(mWeights[i]) && mWeights[i] >= 0) {
                // calculate width with weight in percentage
                int resizeWidth = (int) (mWeights[i] * 1.0f / 100 * availableWidth + 0.5f);
                if (!Float.isNaN(params.mAspectRatio)) {
                    int specialHeight = (int) (resizeWidth / params.mAspectRatio + 0.5f);
                    heightSpec = View.MeasureSpec.makeMeasureSpec(specialHeight, View.MeasureSpec.EXACTLY);
                }
                helper.measureChildWithMargins(view, View.MeasureSpec.makeMeasureSpec(resizeWidth, View.MeasureSpec.EXACTLY), heightSpec);
                // add width into usedWidth
                usedWidth += resizeWidth;
                // find minHeight
                minHeight = Math.min(minHeight, view.getMeasuredHeight());
            } else {
                mEqViews[eqSize++] = view;
            }
        }
        for (int i = 0; i < eqSize; i++) {
            View view = mEqViews[i];
            VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) view.getLayoutParams();
            int heightSpec;
            int resizeWidth = (int) ((availableWidth - usedWidth) * 1.0f / eqSize + 0.5f);
            if (!Float.isNaN(params.mAspectRatio)) {
                int specialHeight = (int) (resizeWidth / params.mAspectRatio + 0.5f);
                heightSpec = View.MeasureSpec.makeMeasureSpec(specialHeight, View.MeasureSpec.EXACTLY);
            } else {
                heightSpec = helper.getChildMeasureSpec(helper.getContentHeight() - helper.getPaddingTop() - helper.getPaddingBottom(), uniformHeight > 0 ? uniformHeight : params.height, true);
            }
            // if cols' length is less than view's count, then remainder views share the rest space
            helper.measureChildWithMargins(view, View.MeasureSpec.makeMeasureSpec(resizeWidth, View.MeasureSpec.EXACTLY), heightSpec);
            // find minHeight
            minHeight = Math.min(minHeight, view.getMeasuredHeight());
        }
        // uniform all views into min height
        for (int i = 0; i < count; i++) {
            View view = mViews[i];
            if (view.getMeasuredHeight() != minHeight) {
                // noinspection ResourceType
                helper.measureChildWithMargins(view, View.MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(minHeight, View.MeasureSpec.EXACTLY));
            }
        }
        result.mConsumed = minHeight + maxVMargin + getVerticalMargin() + getVerticalPadding();
        calculateRect(minHeight + maxVMargin, mTempArea, layoutState, helper);
        // do layout
        int left = mTempArea.left;
        for (int i = 0; i < count; i++) {
            View view = mViews[i];
            int top = mTempArea.top, bottom = mTempArea.bottom;
            int right = left + orientationHelper.getDecoratedMeasurementInOther(view);
            layoutChildWithMargin(view, left, top, right, bottom, helper);
            left = right;
        }
    }
    Arrays.fill(mViews, null);
    Arrays.fill(mEqViews, null);
}
Also used : ViewGroup(android.view.ViewGroup) OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 30 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method checkAnchorInfo.

@Override
public void checkAnchorInfo(RecyclerView.State state, VirtualLayoutManager.AnchorInfoWrapper anchorInfo, LayoutManagerHelper helper) {
    super.checkAnchorInfo(state, anchorInfo, helper);
    ensureLanes();
    final Range<Integer> range = getRange();
    if (anchorInfo.layoutFromEnd) {
        if (anchorInfo.position < range.getLower() + mNumLanes - 1) {
            anchorInfo.position = Math.min(range.getLower() + mNumLanes - 1, range.getUpper());
        }
    } else {
        if (anchorInfo.position > range.getUpper() - (mNumLanes - 1)) {
            anchorInfo.position = Math.max(range.getLower(), range.getUpper() - (mNumLanes - 1));
        }
    }
    View reference = helper.findViewByPosition(anchorInfo.position);
    final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
    int mainGap = layoutInVertical ? mVGap : mHGap;
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    if (reference == null) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "checkAnchorInfo span.clear()");
        }
        if (mSpans != null) {
            for (int i = 0, size = mSpans.length; i < size; i++) {
                Span span = mSpans[i];
                span.clear();
                span.setLine(anchorInfo.coordinate);
            }
        }
    } else {
        int anchorPos = anchorInfo.layoutFromEnd ? Integer.MIN_VALUE : Integer.MAX_VALUE;
        if (mSpans != null) {
            for (int i = 0, size = mSpans.length; i < size; i++) {
                Span span = mSpans[i];
                if (!span.mViews.isEmpty()) {
                    if (anchorInfo.layoutFromEnd) {
                        View view = span.mViews.get(span.mViews.size() - 1);
                        anchorPos = Math.max(anchorPos, helper.getPosition(view));
                    } else {
                        View view = span.mViews.get(0);
                        anchorPos = Math.min(anchorPos, helper.getPosition(view));
                    }
                }
            }
        }
        int offset = INVALID_OFFSET;
        if (!isOutOfRange(anchorPos)) {
            boolean isStartLine = anchorPos == range.getLower();
            View view = helper.findViewByPosition(anchorPos);
            if (view != null) {
                if (anchorInfo.layoutFromEnd) {
                    anchorInfo.position = anchorPos;
                    final int endRef = orientationHelper.getDecoratedEnd(reference);
                    if (endRef < anchorInfo.coordinate) {
                        offset = anchorInfo.coordinate - endRef;
                        offset += (isStartLine ? 0 : mainGap);
                        anchorInfo.coordinate = orientationHelper.getDecoratedEnd(view) + offset;
                    } else {
                        offset = (isStartLine ? 0 : mainGap);
                        anchorInfo.coordinate = orientationHelper.getDecoratedEnd(view) + offset;
                    }
                } else {
                    anchorInfo.position = anchorPos;
                    final int startRef = orientationHelper.getDecoratedStart(reference);
                    if (startRef > anchorInfo.coordinate) {
                        // move align up
                        offset = anchorInfo.coordinate - startRef;
                        offset -= (isStartLine ? 0 : mainGap);
                        anchorInfo.coordinate = orientationHelper.getDecoratedStart(view) + offset;
                    } else {
                        offset = -(isStartLine ? 0 : mainGap);
                        anchorInfo.coordinate = orientationHelper.getDecoratedStart(view) + offset;
                    }
                }
            }
        } else {
            anchorPosition = anchorInfo.position;
            mLayoutWithAnchor = true;
        }
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "checkAnchorInfo span.cacheReferenceLineAndClear()");
        }
        if (mSpans != null) {
            for (int i = 0, size = mSpans.length; i < size; i++) {
                Span span = mSpans[i];
                span.cacheReferenceLineAndClear(helper.getReverseLayout() ^ anchorInfo.layoutFromEnd, offset, orientationHelper);
            }
        }
    }
}
Also used : OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)32 RecyclerView (android.support.v7.widget.RecyclerView)26 View (android.view.View)26 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)18 LayoutParams (com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams)10 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)5 Rect (android.graphics.Rect)2 ArrayMap (android.support.v4.util.ArrayMap)1 SimpleArrayMap (android.support.v4.util.SimpleArrayMap)1 ViewGroup (android.view.ViewGroup)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 TextView (android.widget.TextView)1 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)1 Range (com.alibaba.android.vlayout.Range)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1