diff --git a/demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt b/demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt index 9f9fc3ed..fd52002f 100644 --- a/demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt +++ b/demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt @@ -301,6 +301,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl SPACE_BETWEEN -> AlignContent.SPACE_BETWEEN SPACE_AROUND -> AlignContent.SPACE_AROUND STRETCH -> AlignContent.STRETCH + SPACE_EVENLY -> AlignContent.SPACE_EVENLY else -> return } } @@ -317,6 +318,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl AlignContent.SPACE_BETWEEN -> return SPACE_BETWEEN AlignContent.SPACE_AROUND -> return SPACE_AROUND AlignContent.STRETCH -> return STRETCH + AlignContent.SPACE_EVENLY -> return SPACE_EVENLY else -> return STRETCH } } diff --git a/demo-playground/src/main/res/values/strings.xml b/demo-playground/src/main/res/values/strings.xml index 64b6604c..a1b4fe51 100644 --- a/demo-playground/src/main/res/values/strings.xml +++ b/demo-playground/src/main/res/values/strings.xml @@ -84,6 +84,7 @@ limitations under the License. @string/space_between @string/space_around @string/stretch + @string/space_evenly diff --git a/flexbox/src/main/java/com/google/android/flexbox/AlignContent.java b/flexbox/src/main/java/com/google/android/flexbox/AlignContent.java index ac5e1997..7ed10b87 100644 --- a/flexbox/src/main/java/com/google/android/flexbox/AlignContent.java +++ b/flexbox/src/main/java/com/google/android/flexbox/AlignContent.java @@ -23,7 +23,8 @@ /** This attribute controls the alignment of the flex lines in the flex container. */ @IntDef({AlignContent.FLEX_START, AlignContent.FLEX_END, AlignContent.CENTER, - AlignContent.SPACE_BETWEEN, AlignContent.SPACE_AROUND, AlignContent.STRETCH}) + AlignContent.SPACE_BETWEEN, AlignContent.SPACE_AROUND, AlignContent.STRETCH, + AlignContent.SPACE_EVENLY}) @Retention(RetentionPolicy.SOURCE) public @interface AlignContent { @@ -53,4 +54,6 @@ * Flex lines are stretched to fill the remaining space along the cross axis. */ int STRETCH = 5; + + int SPACE_EVENLY = 6; } diff --git a/flexbox/src/main/java/com/google/android/flexbox/FlexboxHelper.java b/flexbox/src/main/java/com/google/android/flexbox/FlexboxHelper.java index e271d8f6..40701240 100644 --- a/flexbox/src/main/java/com/google/android/flexbox/FlexboxHelper.java +++ b/flexbox/src/main/java/com/google/android/flexbox/FlexboxHelper.java @@ -1516,6 +1516,36 @@ void determineCrossSize(int widthMeasureSpec, int heightMeasureSpec, mFlexContainer.setFlexLines(newFlexLines); break; } + case AlignContent.SPACE_EVENLY: { + if (totalCrossSize >= size) { + // If the size of the content is larger than the flex container, the + // Flex lines should be aligned center like ALIGN_CONTENT_CENTER + mFlexContainer.setFlexLines( + constructFlexLinesForAlignContentCenter(flexLines, size, + totalCrossSize)); + break; + } + // The value of free space along the cross axis which needs to be put on top + // and below the bottom of each flex line. + int spaceTopAndBottom = size - totalCrossSize; + // The number of spaces along the cross axis + int numberOfSpaces = flexLines.size() + 1; + spaceTopAndBottom = spaceTopAndBottom / numberOfSpaces; + List newFlexLines = new ArrayList<>(); + FlexLine dummySpaceFlexLine = new FlexLine(); + dummySpaceFlexLine.mCrossSize = spaceTopAndBottom; + boolean isFirstLine = true; + for (FlexLine flexLine : flexLines) { + if (isFirstLine) { + newFlexLines.add(dummySpaceFlexLine); + isFirstLine = false; + } + newFlexLines.add(flexLine); + newFlexLines.add(dummySpaceFlexLine); + } + mFlexContainer.setFlexLines(newFlexLines); + break; + } case AlignContent.SPACE_BETWEEN: { if (totalCrossSize >= size) { break;