float (int size1, int mSize1, int pSize1, int mxSize1, int size2, int mSize2, int pSize2, int mxSize2, int totalSize, float oldProportion, @Nullable Boolean stretchFirst) { //clamp mSize1 = Math.min(mSize1, mxSize1); mSize2 = Math.min(mSize2, mxSize2); pSize1 = MathUtil.clamp(pSize1, mSize1, mxSize1); pSize2 = MathUtil.clamp(pSize2, mSize2, mxSize2); int delta = totalSize - (size1 + size2); int[] size = {size1, size2}; if (delta >= 0) { delta = stretchTo(size, mSize1, mSize2, delta, oldProportion); delta = stretchTo(size, pSize1, pSize2, delta, oldProportion); delta = stretchTo(size, mxSize1, mxSize2, delta, oldProportion); } else { delta = stretchTo(size, mxSize1, mxSize2, delta, oldProportion); delta = stretchTo(size, pSize1, pSize2, delta, oldProportion); delta = stretchTo(size, mSize1, mSize2, delta, oldProportion); } if (delta != 0) { if (stretchFirst == null) { int p0 = computePortion(size, delta, oldProportion); size[0] += p0; size[1] += delta - p0; } else { size[stretchFirst ? 0 : 1] += delta; } } return (float)size[0] / totalSize; }