if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
if (mChildrenViews == null || mChildrenViews.length != getItemCount()) {
mChildrenViews = new View[getItemCount()];
}
int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
final int parentWidth = helper.getContentWidth();
final int parentHPadding = helper.getPaddingLeft() + helper.getPaddingRight() +
getHorizontalMargin() + getHorizontalPadding();
final int parentVPadding = helper.getPaddingTop() + helper.getPaddingBottom() +
getVerticalMargin() + getVerticalPadding();
int mainConsumed = 0;
if (count >= 2) {
this.mColWeights = (this.mColWeights.length == count - 1) ? this.mColWeights : new float[0];
View[] views = new View[count];
int right2 = 0;//第二个VIEW的右位置
int countWidth = 0;//宽度的集合
int heightFirst = 0;//第一行的高
int heightOther = 0;//第二行的高
VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(
mChildrenViews[0].getLayoutParams());
VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(
mChildrenViews[1].getLayoutParams());
int parentHeight = !Float.isNaN(mAspectRatio) ? (int) ((parentWidth - parentHPadding) / mAspectRatio)
: lp1.height + lp2.height;
mainConsumed = (parentHeight) + getVerticalMargin() + getVerticalPadding();
calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect,
layoutState, helper);
for (int i = 0; i < count; i++) {
View child = mChildrenViews[i];
VirtualLayoutManager.LayoutParams lp = new VirtualLayoutManager.LayoutParams(
child.getLayoutParams());
if (layoutInVertical) {
int availableSpaceWidth = parentWidth - parentHPadding - lp.leftMargin - lp.rightMargin;
//int availableSpaceHeight = parentWidth - parentVPadding;
if (i == 0) {
heightFirst = Float.isNaN(mRowWeight) ? (parentHeight * 50 / 100)
: (int) (parentHeight * mRowWeight / 100);
heightOther = Float.isNaN(mRowWeight) ? (parentHeight * 50 / 100)
: (int) (parentHeight * (100 - mRowWeight) / 100);
helper.measureChild(child,
helper.getChildMeasureSpec(helper.getContentWidth(), lp1.width, true),
//MeasureSpec.makeMeasureSpec(width + lp.leftMargin + lp.rightMargin, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(heightFirst + lp.topMargin + lp.bottomMargin,
MeasureSpec.EXACTLY));
int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child);
layoutChild(child, mAreaRect.left, mAreaRect.top, right1,
mAreaRect.top + heightFirst, helper);
} else {
float weight = getViewMainWeight(i - 1);
int width = Float.isNaN(weight) ? (Math.round(availableSpaceWidth) / (count - 1))
: (int) (availableSpaceWidth * weight / 100);
helper.measureChild(child,
MeasureSpec.makeMeasureSpec(width + lp.leftMargin + lp.rightMargin,
MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(heightOther + lp.topMargin + lp.bottomMargin,
MeasureSpec.EXACTLY));
if (i == 1) {
right2 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child);
layoutChild(child, mAreaRect.left, mAreaRect.top + heightFirst, right2,
mAreaRect.bottom, helper);
} else if (i == count - 1) {
int right = right2 + (parentWidth - parentHPadding - countWidth);
layoutChild(child, right2, mAreaRect.top + heightFirst, right,
mAreaRect.bottom, helper);
} else {
int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child);
layoutChild(child, right2, mAreaRect.top + heightFirst, right3,
mAreaRect.bottom, helper);
right2 = right3;
}
countWidth = countWidth + width;//第二行全部的宽度
}
}//if (layoutInVertical)
views[i] = child;
}
handleStateOnResult(result, views);
}
result.mConsumed = mainConsumed;
Arrays.fill(mChildrenViews, null);
if (isLayoutEnd) {
if (offset == getItemCount() - 1) {
return layoutInVertical ? mMarginBottom + mPaddingBottom : mMarginRight + mPaddingRight;
}
} else {
if (offset == 0) {
return layoutInVertical ? -mMarginTop - mPaddingTop : -mMarginLeft - mPaddingLeft;
}
}
return super.computeAlignOffset(offset, isLayoutEnd, useAnchor, helper);