@Test public void testAlignContent() { FlexboxLayout flexboxLayout = new FlexboxLayout(); flexboxLayout.setFlexDirection(FlexDirection.ROW); flexboxLayout.setFlexWrap(FlexWrap.WRAP); flexboxLayout.setAlignContent(AlignContent.FLEX_START); for (int i = 0; i < 3; i++) { DefaultFlexItem flexItemImpl = new DefaultFlexItem(); flexItemImpl.setMinWidth(51); flexItemImpl.setMinHeight(20); flexboxLayout.add(flexItemImpl); } flexboxLayout.sortChildren(); flexboxLayout.calculateFlexLines(100); flexboxLayout.alignContent(500); Assert.assertEquals(60, flexboxLayout.getMinCrossSize(), 0.001); List<FlexboxLayout.FlexLine> flexLines = flexboxLayout.flexLines; Assert.assertEquals(40, flexLines.get(2).getCrossStartPos(), 0.001); flexboxLayout.setAlignContent(AlignContent.FLEX_END); flexboxLayout.calculateFlexLines(100); flexboxLayout.alignContent(500); Assert.assertEquals(480, flexboxLayout.flexLines.get(2).getCrossStartPos(), 0.01); flexboxLayout.setAlignContent(AlignContent.CENTER); flexboxLayout.calculateFlexLines(100); flexboxLayout.alignContent(500); Assert.assertEquals(260, flexboxLayout.flexLines.get(2).getCrossStartPos(), 0.01); flexboxLayout.setAlignContent(AlignContent.SPACE_AROUND); flexboxLayout.calculateFlexLines(100); flexboxLayout.alignContent(500); Assert.assertEquals(406.6666666666666, flexboxLayout.flexLines.get(2).getCrossStartPos(), 0.01); flexboxLayout.setAlignContent(AlignContent.SPACE_BETWEEN); flexboxLayout.calculateFlexLines(100); flexboxLayout.alignContent(500); Assert.assertEquals(480, flexboxLayout.flexLines.get(2).getCrossStartPos(), 0.01); }
void alignContent(double crossSize) { minCrossSize = 0; if (flexLines.size()==0)return; for (FlexLine flexLine : flexLines) { minCrossSize += flexLine.getMinCrossSize(); } double crossStartPos = 0; switch (alignContent) { case FLEX_START: for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } minCrossSize = crossStartPos; break; case FLEX_END: crossStartPos = Math.max(0, crossSize - minCrossSize); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case CENTER: crossStartPos = Math.max(0, (crossSize - minCrossSize) / 2); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case SPACE_BETWEEN: double extra = (crossSize - minCrossSize) / (flexLines.size() - 1); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extra); } break; case STRETCH: { double extraSpace = ((crossSize - minCrossSize) / flexLines.size()); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); flexLine.setMinCrossSize(flexLine.minCrossSize + extraSpace); } break; } case SPACE_AROUND: double extraSpace = ((crossSize - minCrossSize) / flexLines.size()) / 2; for (FlexLine flexLine : flexLines) { crossStartPos += extraSpace; crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); } break; } }
FlexboxLayout { void alignContent(double crossSize) { minCrossSize = 0; if (flexLines.size()==0)return; for (FlexLine flexLine : flexLines) { minCrossSize += flexLine.getMinCrossSize(); } double crossStartPos = 0; switch (alignContent) { case FLEX_START: for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } minCrossSize = crossStartPos; break; case FLEX_END: crossStartPos = Math.max(0, crossSize - minCrossSize); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case CENTER: crossStartPos = Math.max(0, (crossSize - minCrossSize) / 2); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case SPACE_BETWEEN: double extra = (crossSize - minCrossSize) / (flexLines.size() - 1); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extra); } break; case STRETCH: { double extraSpace = ((crossSize - minCrossSize) / flexLines.size()); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); flexLine.setMinCrossSize(flexLine.minCrossSize + extraSpace); } break; } case SPACE_AROUND: double extraSpace = ((crossSize - minCrossSize) / flexLines.size()) / 2; for (FlexLine flexLine : flexLines) { crossStartPos += extraSpace; crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); } break; } } }
FlexboxLayout { void alignContent(double crossSize) { minCrossSize = 0; if (flexLines.size()==0)return; for (FlexLine flexLine : flexLines) { minCrossSize += flexLine.getMinCrossSize(); } double crossStartPos = 0; switch (alignContent) { case FLEX_START: for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } minCrossSize = crossStartPos; break; case FLEX_END: crossStartPos = Math.max(0, crossSize - minCrossSize); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case CENTER: crossStartPos = Math.max(0, (crossSize - minCrossSize) / 2); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case SPACE_BETWEEN: double extra = (crossSize - minCrossSize) / (flexLines.size() - 1); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extra); } break; case STRETCH: { double extraSpace = ((crossSize - minCrossSize) / flexLines.size()); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); flexLine.setMinCrossSize(flexLine.minCrossSize + extraSpace); } break; } case SPACE_AROUND: double extraSpace = ((crossSize - minCrossSize) / flexLines.size()) / 2; for (FlexLine flexLine : flexLines) { crossStartPos += extraSpace; crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); } break; } }  }
FlexboxLayout { void alignContent(double crossSize) { minCrossSize = 0; if (flexLines.size()==0)return; for (FlexLine flexLine : flexLines) { minCrossSize += flexLine.getMinCrossSize(); } double crossStartPos = 0; switch (alignContent) { case FLEX_START: for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } minCrossSize = crossStartPos; break; case FLEX_END: crossStartPos = Math.max(0, crossSize - minCrossSize); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case CENTER: crossStartPos = Math.max(0, (crossSize - minCrossSize) / 2); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case SPACE_BETWEEN: double extra = (crossSize - minCrossSize) / (flexLines.size() - 1); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extra); } break; case STRETCH: { double extraSpace = ((crossSize - minCrossSize) / flexLines.size()); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); flexLine.setMinCrossSize(flexLine.minCrossSize + extraSpace); } break; } case SPACE_AROUND: double extraSpace = ((crossSize - minCrossSize) / flexLines.size()) / 2; for (FlexLine flexLine : flexLines) { crossStartPos += extraSpace; crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); } break; } }  double getMinMainSize(); double getMinCrossSize(); void layoutSubViews(double mainSize, double crossSize); boolean isHorizontal(); FlexDirection getFlexDirection(); void setFlexDirection(FlexDirection flexDirection); FlexWrap getFlexWrap(); void setFlexWrap(FlexWrap flexWrap); JustifyContent getJustifyContent(); void setJustifyContent(JustifyContent justifyContent); AlignItems getAlignItems(); void setAlignItems(AlignItems alignItems); AlignContent getAlignContent(); void setAlignContent(AlignContent alignContent); void add(FlexItem flexItem); void clearItems(); }
FlexboxLayout { void alignContent(double crossSize) { minCrossSize = 0; if (flexLines.size()==0)return; for (FlexLine flexLine : flexLines) { minCrossSize += flexLine.getMinCrossSize(); } double crossStartPos = 0; switch (alignContent) { case FLEX_START: for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } minCrossSize = crossStartPos; break; case FLEX_END: crossStartPos = Math.max(0, crossSize - minCrossSize); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case CENTER: crossStartPos = Math.max(0, (crossSize - minCrossSize) / 2); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartpossByAlignmentType(flexLine, crossStartPos); } break; case SPACE_BETWEEN: double extra = (crossSize - minCrossSize) / (flexLines.size() - 1); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extra); } break; case STRETCH: { double extraSpace = ((crossSize - minCrossSize) / flexLines.size()); for (FlexLine flexLine : flexLines) { crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); flexLine.setMinCrossSize(flexLine.minCrossSize + extraSpace); } break; } case SPACE_AROUND: double extraSpace = ((crossSize - minCrossSize) / flexLines.size()) / 2; for (FlexLine flexLine : flexLines) { crossStartPos += extraSpace; crossStartPos = getNewStartPosWithExtra(flexLine, crossStartPos, extraSpace); } break; } }  double getMinMainSize(); double getMinCrossSize(); void layoutSubViews(double mainSize, double crossSize); boolean isHorizontal(); FlexDirection getFlexDirection(); void setFlexDirection(FlexDirection flexDirection); FlexWrap getFlexWrap(); void setFlexWrap(FlexWrap flexWrap); JustifyContent getJustifyContent(); void setJustifyContent(JustifyContent justifyContent); AlignItems getAlignItems(); void setAlignItems(AlignItems alignItems); AlignContent getAlignContent(); void setAlignContent(AlignContent alignContent); void add(FlexItem flexItem); void clearItems();  }