Search code examples
androidandroid-layoutandroid-viewandroid-flexboxlayout

Android Google FlexboxLayout : get lines or columns number


I am using the Google's FlexboxLayout Android library.

I'm searching how to get the number of rows (when the flexDirection property is set to row or row_reverse) or columns (when the flexDirection property is set to column or column_reverse).


Solution

  • The method FlexboxLayout.getFlexLines() returns a list of instances of com.google.android.flexbox.FlexLine, each holds properties related to a a line on the main axis of the FlexBoxLayout. I just have to retrieve the size of the list to get the number of lines on the main axis.

    Note that FlexboxLayout.getFlexLines() returns the number of actual lines -1.