use of android.support.v7.widget.RecyclerView.Recycler in project Music-Player by andremion.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_list);
//
mCoverView = findViewById(R.id.cover);
mTitleView = findViewById(R.id.title);
mTimeView = findViewById(R.id.time);
mDurationView = findViewById(R.id.duration);
mProgressView = findViewById(R.id.progress);
mFabView = findViewById(R.id.fab);
// Set the recycler adapter
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.tracks);
assert recyclerView != null;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new RecyclerViewAdapter(MusicContent.ITEMS));
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class FixLayoutHelper method layoutViews.
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, VirtualLayoutManager.LayoutStateWrapper layoutState, LayoutChunkResult result, final LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
if (!mShouldDrawn) {
layoutState.skipCurrentPosition();
return;
}
// find view in currentPosition
View view = mFixView;
if (view == null) {
view = layoutState.next(recycler);
} else {
layoutState.skipCurrentPosition();
}
if (view == null) {
result.mFinished = true;
return;
}
mDoNormalHandle = state.isPreLayout();
if (mDoNormalHandle) {
// in PreLayout do normal layout
helper.addChildView(layoutState, view);
}
mFixView = view;
doMeasureAndLayout(view, helper);
result.mConsumed = 0;
result.mIgnoreConsumed = true;
handleStateOnResult(result, view);
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class GridLayoutHelper method assignSpans.
private void assignSpans(RecyclerView.Recycler recycler, RecyclerView.State state, int count, int consumedSpanCount, boolean layingOutInPrimaryDirection, LayoutManagerHelper layoutManagerHelper) {
int span, spanDiff, start, end, diff;
// make sure we traverse from min position to max position
if (layingOutInPrimaryDirection) {
start = 0;
end = count;
diff = 1;
} else {
start = count - 1;
end = -1;
diff = -1;
}
if (layoutManagerHelper.getOrientation() == VERTICAL && layoutManagerHelper.isDoLayoutRTL()) {
// start from last span
span = consumedSpanCount - 1;
spanDiff = -1;
} else {
span = 0;
spanDiff = 1;
}
for (int i = start; i != end; i += diff) {
View view = mSet[i];
int spanSize = getSpanSize(recycler, state, layoutManagerHelper.getPosition(view));
if (spanDiff == -1 && spanSize > 1) {
mSpanIndices[i] = span - (spanSize - 1);
} else {
mSpanIndices[i] = span;
}
span += spanDiff * spanSize;
}
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class LinearLayoutHelper method layoutViews.
/**
* In {@link LinearLayoutHelper}, each iteration only consume one item,
* so it can let parent LayoutManager to decide whether the next item is in the range of this helper
*/
@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;
}
int currentPosition = layoutState.getCurrentPosition();
// find corresponding layout container
View view = nextView(recycler, layoutState, helper, result);
if (view == null) {
return;
}
VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) view.getLayoutParams();
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
int startSpace = 0, endSpace = 0, gap = 0;
boolean isLayoutEnd = layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_END;
boolean isStartLine = isLayoutEnd ? currentPosition == getRange().getLower().intValue() : currentPosition == getRange().getUpper().intValue();
boolean isEndLine = isLayoutEnd ? currentPosition == getRange().getUpper().intValue() : currentPosition == getRange().getLower().intValue();
if (isStartLine) {
startSpace = layoutInVertical ? (isLayoutEnd ? mMarginTop + mPaddingTop : mMarginBottom + mPaddingBottom) : (isLayoutEnd ? mMarginLeft + mPaddingLeft : mMarginRight + mPaddingRight);
}
if (isEndLine) {
endSpace = layoutInVertical ? (isLayoutEnd ? mMarginBottom + mPaddingBottom : mMarginTop + mPaddingTop) : (isLayoutEnd ? mMarginRight + mPaddingRight : mMarginLeft + mPaddingLeft);
}
if (!isStartLine) {
gap = mDividerHeight;
}
final int widthSize = helper.getContentWidth() - helper.getPaddingLeft() - helper.getPaddingRight() - getHorizontalMargin() - getHorizontalPadding();
int widthSpec = helper.getChildMeasureSpec(widthSize, params.width, !layoutInVertical);
int heightSpec;
float viewAspectRatio = params.mAspectRatio;
if (!Float.isNaN(viewAspectRatio) && viewAspectRatio > 0) {
heightSpec = View.MeasureSpec.makeMeasureSpec((int) (widthSize / viewAspectRatio + 0.5f), View.MeasureSpec.EXACTLY);
} else if (!Float.isNaN(mAspectRatio) && mAspectRatio > 0) {
heightSpec = View.MeasureSpec.makeMeasureSpec((int) (widthSize / mAspectRatio + 0.5), View.MeasureSpec.EXACTLY);
} else {
heightSpec = helper.getChildMeasureSpec(helper.getContentHeight() - helper.getPaddingTop() - helper.getPaddingBottom() - getVerticalMargin() - getVerticalPadding(), params.height, layoutInVertical);
}
helper.measureChild(view, widthSpec, heightSpec);
OrientationHelper orientationHelper = helper.getMainOrientationHelper();
result.mConsumed = orientationHelper.getDecoratedMeasurement(view) + startSpace + endSpace + gap;
int left, top, right, bottom;
if (helper.getOrientation() == VERTICAL) {
// not support RTL now
if (helper.isDoLayoutRTL()) {
right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight - mPaddingRight;
left = right - orientationHelper.getDecoratedMeasurementInOther(view);
} else {
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(view);
}
// whether this layout pass is layout to start or to end
if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) {
// fill start, from bottom to top
bottom = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight);
top = bottom - orientationHelper.getDecoratedMeasurement(view);
} else {
// fill end, from top to bottom
top = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight);
bottom = top + orientationHelper.getDecoratedMeasurement(view);
}
} else {
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(view);
if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) {
// fill left, from right to left
right = layoutState.getOffset() - startSpace - (isStartLine ? 0 : mDividerHeight);
left = right - orientationHelper.getDecoratedMeasurement(view);
} else {
// fill right, from left to right
left = layoutState.getOffset() + startSpace + (isStartLine ? 0 : mDividerHeight);
right = left + orientationHelper.getDecoratedMeasurement(view);
}
}
// We calculate everything with View's bounding box (which includes decor and margins)
// To calculate correct layout position, we subtract margins.
layoutChild(view, left, top, right, bottom, helper);
if (DEBUG) {
Log.d(TAG, "laid out child at position " + helper.getPosition(view) + ", with l:" + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin));
}
handleStateOnResult(result, view);
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class OnePlusNLayoutHelper method layoutViews.
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
final int originCurPos = layoutState.getCurrentPosition();
if (mChildrenViews == null || mChildrenViews.length != getItemCount()) {
mChildrenViews = new View[getItemCount()];
}
int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
if (count != getItemCount()) {
Log.w(TAG, "The real number of children is not match with range of LayoutHelper");
}
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
final int parentWidth = helper.getContentWidth();
final int parentHeight = helper.getContentHeight();
final int parentHPadding = helper.getPaddingLeft() + helper.getPaddingRight() + getHorizontalMargin() + getHorizontalPadding();
final int parentVPadding = helper.getPaddingTop() + helper.getPaddingBottom() + getVerticalMargin() + getVerticalPadding();
int mainConsumed = 0;
if (count == 1) {
View view = mChildrenViews[0];
final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(view.getLayoutParams());
if (!Float.isNaN(mAspectRatio)) {
if (layoutInVertical) {
lp.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
} else {
lp.width = (int) ((parentHeight - parentVPadding) * mAspectRatio);
}
}
final float weight = getViewMainWeight(lp, 0);
// fill width
int widthSpec = helper.getChildMeasureSpec(Float.isNaN(weight) ? (parentWidth - parentHPadding) : (int) ((parentWidth - parentHPadding) * weight), layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding, layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
helper.measureChild(view, widthSpec, heightSpec);
mainConsumed = orientationHelper.getDecoratedMeasurement(view) + (layoutInVertical ? getVerticalMargin() + getVerticalPadding() : getHorizontalMargin() + getHorizontalPadding());
calculateRect(mainConsumed, mAreaRect, layoutState, helper);
layoutChild(view, mAreaRect.left, mAreaRect.top, mAreaRect.right, mAreaRect.bottom, helper);
handleStateOnResult(result, view);
} else if (count == 2) {
final View child1 = mChildrenViews[0];
final ViewGroup.MarginLayoutParams lp1 = new ViewGroup.MarginLayoutParams(child1.getLayoutParams());
final View child2 = mChildrenViews[1];
final ViewGroup.MarginLayoutParams lp2 = new ViewGroup.MarginLayoutParams(child2.getLayoutParams());
final float weight1 = getViewMainWeight(lp1, 0);
final float weight2 = getViewMainWeight(lp1, 1);
if (layoutInVertical) {
if (!Float.isNaN(mAspectRatio)) {
lp1.height = lp2.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
}
lp2.topMargin = lp1.topMargin;
lp2.bottomMargin = lp1.bottomMargin;
int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
int width2 = Float.isNaN(weight2) ? (availableSpace - width1) : (int) (availableSpace * weight2 / 100 + 0.5f);
helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp2.height, true));
mainConsumed = Math.max(orientationHelper.getDecoratedMeasurement(child1), orientationHelper.getDecoratedMeasurement(child2)) + getVerticalMargin() + getVerticalPadding();
calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
layoutChild(child2, right1, mAreaRect.top, right1 + orientationHelper.getDecoratedMeasurementInOther(child2), mAreaRect.bottom, helper);
} else {
if (!Float.isNaN(mAspectRatio)) {
lp1.width = lp2.width = (int) ((parentHeight - parentVPadding) * mAspectRatio);
}
int availableSpace = parentHeight - parentVPadding - lp1.topMargin - lp1.bottomMargin - lp2.topMargin - lp2.bottomMargin;
int height1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
int height2 = Float.isNaN(weight2) ? (int) (availableSpace - height1) : (int) (availableSpace * weight2 / 100 + 0.5f);
helper.measureChild(child1, helper.getChildMeasureSpec(helper.getContentWidth(), lp1.width, true), MeasureSpec.makeMeasureSpec(height1 + lp1.topMargin + lp1.bottomMargin, MeasureSpec.EXACTLY));
int width = child1.getMeasuredWidth();
helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
mainConsumed = Math.max(orientationHelper.getDecoratedMeasurement(child1), orientationHelper.getDecoratedMeasurement(child2)) + getHorizontalMargin() + getHorizontalPadding();
calculateRect(mainConsumed - getHorizontalPadding() - getHorizontalMargin(), mAreaRect, layoutState, helper);
int bottom1 = mAreaRect.top + orientationHelper.getDecoratedMeasurementInOther(child1);
layoutChild(child1, mAreaRect.left, mAreaRect.top, mAreaRect.right, bottom1, helper);
layoutChild(child2, mAreaRect.left, bottom1, mAreaRect.right, bottom1 + orientationHelper.getDecoratedMeasurementInOther(child2), helper);
}
handleStateOnResult(result, child1, child2);
} else if (count == 3) {
final View child1 = mChildrenViews[0];
final ViewGroup.MarginLayoutParams lp1 = new ViewGroup.MarginLayoutParams(child1.getLayoutParams());
final View child2 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[1];
final View child3 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[2];
final ViewGroup.MarginLayoutParams lp2 = new ViewGroup.MarginLayoutParams(child2.getLayoutParams());
final ViewGroup.MarginLayoutParams lp3 = new ViewGroup.MarginLayoutParams(child3.getLayoutParams());
final float weight1 = getViewMainWeight(lp1, 0);
final float weight2 = getViewMainWeight(lp1, 1);
final float weight3 = getViewMainWeight(lp1, 2);
if (layoutInVertical) {
if (!Float.isNaN(mAspectRatio)) {
lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
}
// make border consistent
lp2.topMargin = lp1.topMargin;
lp3.bottomMargin = lp1.bottomMargin;
lp3.leftMargin = lp2.leftMargin;
lp3.rightMargin = lp2.rightMargin;
int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
int width2 = Float.isNaN(weight2) ? (int) (availableSpace - width1) : (int) (availableSpace * weight2 / 100 + 0.5);
int width3 = Float.isNaN(weight3) ? (int) (width2) : (int) (availableSpace * weight3 / 100 + 0.5);
helper.measureChild(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.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
mainConsumed = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, height2 + lp2.topMargin + lp2.bottomMargin + height3 + lp3.topMargin + lp3.bottomMargin) + getVerticalMargin() + getVerticalPadding();
calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + child2.getMeasuredHeight() + lp2.topMargin + lp2.bottomMargin, helper);
layoutChild(child3, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child3), right1 + orientationHelper.getDecoratedMeasurementInOther(child3), mAreaRect.bottom, helper);
} else {
// TODO: horizontal support
}
handleStateOnResult(result, child1, child2, child3);
} else if (count == 4) {
final View child1 = mChildrenViews[0];
final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
final View child2 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[1];
final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
final View child3 = mChildrenViews[2];
final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
final View child4 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[3];
final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
final float weight1 = getViewMainWeight(lp1, 0);
final float weight2 = getViewMainWeight(lp1, 1);
final float weight3 = getViewMainWeight(lp1, 2);
final float weight4 = getViewMainWeight(lp1, 3);
if (layoutInVertical) {
lp2.topMargin = lp1.topMargin;
lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
lp3.leftMargin = lp2.leftMargin;
lp4.rightMargin = lp2.rightMargin;
if (!Float.isNaN(mAspectRatio)) {
lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
}
int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
int width2 = Float.isNaN(weight2) ? (int) (availableSpace - width1) : (int) (availableSpace * weight2 / 100 + 0.5f);
int width3 = Float.isNaN(weight3) ? (int) ((width2 - lp3.rightMargin - lp4.leftMargin) / 2.0f + 0.5f) : (int) (availableSpace * weight3 / 100 + 0.5f);
int width4 = Float.isNaN(weight4) ? (int) ((width2 - lp3.rightMargin - lp4.leftMargin - width3)) : (int) (availableSpace * weight4 / 100 + 0.5f);
helper.measureChild(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 = (int) ((height1 - lp2.bottomMargin - lp3.topMargin) - height2);
helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.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);
layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
int right3 = right1 + orientationHelper.getDecoratedMeasurementInOther(child3);
layoutChild(child3, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child3), right3, mAreaRect.bottom, helper);
layoutChild(child4, right3, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right3 + orientationHelper.getDecoratedMeasurementInOther(child4), mAreaRect.bottom, helper);
} else {
// TODO: horizontal support
}
handleStateOnResult(result, child1, child2, child3, child4);
} else if (count == 5) {
final View child1 = mChildrenViews[0];
final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
final View child2 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[1];
final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
final View child3 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[2];
final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
final View child4 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[3];
final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
final View child5 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[4];
final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
final float weight1 = getViewMainWeight(lp1, 0);
final float weight2 = getViewMainWeight(lp1, 1);
final float weight3 = getViewMainWeight(lp1, 2);
final float weight4 = getViewMainWeight(lp1, 3);
final float weight5 = getViewMainWeight(lp1, 4);
if (layoutInVertical) {
lp2.topMargin = lp1.topMargin;
lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
lp3.leftMargin = lp2.leftMargin;
lp4.rightMargin = lp2.rightMargin;
lp5.rightMargin = lp2.rightMargin;
if (!Float.isNaN(mAspectRatio)) {
lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
}
int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
int width2 = Float.isNaN(weight2) ? (int) (availableSpace - width1) : (int) (availableSpace * weight2 / 100 + 0.5f);
int width3 = Float.isNaN(weight3) ? (int) ((width2 - lp3.rightMargin - lp4.leftMargin) / 3.0f + 0.5f) : (int) (availableSpace * weight3 / 100 + 0.5f);
int width4 = Float.isNaN(weight4) ? (int) ((width2 - lp3.rightMargin - lp4.leftMargin) / 3.0f + 0.5f) : (int) (availableSpace * weight4 / 100 + 0.5f);
int width5 = Float.isNaN(weight5) ? (int) ((width2 - lp3.rightMargin - lp4.leftMargin - width3 - width4)) : (int) (availableSpace * weight5 / 100 + 0.5f);
helper.measureChild(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 = (int) ((height1 - lp2.bottomMargin - lp3.topMargin) - height2);
helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
helper.measureChild(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);
layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
int right3 = right1 + orientationHelper.getDecoratedMeasurementInOther(child3);
layoutChild(child3, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child3), right3, mAreaRect.bottom, helper);
int right4 = right3 + orientationHelper.getDecoratedMeasurementInOther(child4);
layoutChild(child4, right3, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right3 + orientationHelper.getDecoratedMeasurementInOther(child4), mAreaRect.bottom, helper);
layoutChild(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right4 + orientationHelper.getDecoratedMeasurementInOther(child5), mAreaRect.bottom, helper);
} else {
// TODO: horizontal support
}
handleStateOnResult(result, child1, child2, child3, child4, child5);
}
result.mConsumed = mainConsumed;
Arrays.fill(mChildrenViews, null);
}
Aggregations