question: private void determineCrossSize ( int flexDirection , int widthMeasureSpec , int heightMeasureSpec , int paddingAlongCrossAxis ) { int mode ; int size ; switch ( flexDirection ) { case FLEX_DIRECTION_ROW : case FLEX_DIRECTION_ROW_REVERSE : mode = MeasureSpec . getMode ( heightMeasureSpec ) ; size = MeasureSpec . getSize ( heightMeasureSpec ) ; break ; case FLEX_DIRECTION_COLUMN : case FLEX_DIRECTION_COLUMN_REVERSE : mode = MeasureSpec . getMode ( widthMeasureSpec ) ; size = MeasureSpec . getSize ( widthMeasureSpec ) ; break ; default : throw new IllegalArgumentException ( "Invalid flex direction: " + flexDirection ) ; } if ( mode == MeasureSpec . EXACTLY ) { int totalCrossSize = getSumOfCrossSize ( ) + paddingAlongCrossAxis ; if ( mFlexLines . size ( ) == 1 ) { mFlexLines . get ( 0 ) . mCrossSize = size - paddingAlongCrossAxis ; } else if ( mFlexLines . size ( ) >= 2 && totalCrossSize < size ) { switch ( mAlignContent ) { case ALIGN_CONTENT_STRETCH : { float freeSpaceUnit = ( size - totalCrossSize ) / ( float ) mFlexLines . size ( ) ; float accumulatedError = 0 ; for ( int i = 0 , flexLinesSize = mFlexLines . size ( ) ; i < flexLinesSize ; i ++ ) { FlexLine flexLine = mFlexLines . get ( i ) ; float newCrossSizeAsFloat = flexLine . mCrossSize + freeSpaceUnit ; if ( i == mFlexLines . size ( ) - 1 ) { newCrossSizeAsFloat += accumulatedError ; accumulatedError = 0 ; } int newCrossSize = Math . round ( newCrossSizeAsFloat ) ; accumulatedError += ( newCrossSizeAsFloat - newCrossSize ) ; if ( accumulatedError > 1 ) { newCrossSize += 1 ; accumulatedError -= 1 ; } else if ( accumulatedError < - 1 ) { newCrossSize -= 1 ; accumulatedError += 1 ; } flexLine . mCrossSize = newCrossSize ; } break ; } case ALIGN_CONTENT_SPACE_AROUND : { int spaceTopAndBottom = size - totalCrossSize ; int numberOfSpaces = mFlexLines . size ( ) * 2 ; spaceTopAndBottom = spaceTopAndBottom / numberOfSpaces ; List < FlexLine > newFlexLines = new ArrayList < > ( ) ; FlexLine dummySpaceFlexLine = new FlexLine ( ) ; dummySpaceFlexLine . mCrossSize = spaceTopAndBottom ; for ( FlexLine flexLine : mFlexLines ) { newFlexLines . add ( dummySpaceFlexLine ) ; newFlexLines . add ( flexLine ) ; newFlexLines . add ( dummySpaceFlexLine ) ; } mFlexLines = newFlexLines ; break ; } case ALIGN_CONTENT_SPACE_BETWEEN : { float spaceBetweenFlexLine = size - totalCrossSize ; int numberOfSpaces = mFlexLines . size ( ) - 1 ; spaceBetweenFlexLine = spaceBetweenFlexLine / ( float ) numberOfSpaces ; float accumulatedError = 0 ; List < FlexLine > newFlexLines = new ArrayList < > ( ) ; for ( int i = 0 , flexLineSize = mFlexLines . size ( ) ; i < flexLineSize ; i ++ ) { FlexLine flexLine = mFlexLines . get ( i ) ; newFlexLines . add ( flexLine ) ; if ( i != mFlexLines . size ( ) - 1 ) { FlexLine dummySpaceFlexLine = new FlexLine ( ) ; if ( i == mFlexLines . size ( ) - 2 ) { dummySpaceFlexLine . mCrossSize = Math . round ( spaceBetweenFlexLine + accumulatedError ) ; accumulatedError = 0 ; } else { dummySpaceFlexLine . mCrossSize = Math . round ( spaceBetweenFlexLine ) ; } accumulatedError += ( spaceBetweenFlexLine - dummySpaceFlexLine . mCrossSize ) ; if ( accumulatedError > 1 ) { dummySpaceFlexLine . mCrossSize += 1 ; accumulatedError -= 1 ; } else if ( accumulatedError < - 1 ) { dummySpaceFlexLine . mCrossSize -= 1 ; accumulatedError += 1 ; } newFlexLines . add ( dummySpaceFlexLine ) ; } } mFlexLines = newFlexLines ; break ; } case ALIGN_CONTENT_CENTER : { int spaceAboveAndBottom = size - totalCrossSize ; spaceAboveAndBottom = spaceAboveAndBottom / 2 ; List < FlexLine > newFlexLines = new ArrayList < > ( ) ; FlexLine dummySpaceFlexLine = new FlexLine ( ) ; dummySpaceFlexLine . mCrossSize = spaceAboveAndBottom ; for ( int i = 0 , flexLineSize = mFlexLines . size ( ) ; i < flexLineSize ; i ++ ) { if ( i == 0 ) { newFlexLines . add ( dummySpaceFlexLine ) ; } FlexLine flexLine = mFlexLines . get ( i ) ; newFlexLines . add ( flexLine ) ; if ( i == mFlexLines . size ( ) - 1 ) { newFlexLines . add ( dummySpaceFlexLine ) ; } } mFlexLines = newFlexLines ; break ; } case ALIGN_CONTENT_FLEX_END : { int spaceTop = size - totalCrossSize ; FlexLine dummySpaceFlexLine = new FlexLine ( ) ; dummySpaceFlexLine . mCrossSize = spaceTop ; mFlexLines . add ( 0 , dummySpaceFlexLine ) ; break ; } } } } }
target:  Determines the cross size (Calculate the length along the cross axis). Expand the cross size only if the height mode is MeasureSpec.EXACTLY, otherwise use the sum of cross sizes of all flex lines.