Class FlexboxLayoutManager

    • Constructor Detail

      • FlexboxLayoutManager

        FlexboxLayoutManager(Context context)
        Creates a default FlexboxLayoutManager.
      • FlexboxLayoutManager

        FlexboxLayoutManager(Context context, int flexDirection)
        Creates a FlexboxLayoutManager with the flexDirection specified.
        Parameters:
        flexDirection - the flex direction attribute
      • FlexboxLayoutManager

        FlexboxLayoutManager(Context context, int flexDirection, int flexWrap)
        Creates a FlexboxLayoutManager with the flexDirection and flexWrap attributes specified.
        Parameters:
        flexDirection - the flex direction attribute
        flexWrap - the flex wrap attribute
      • FlexboxLayoutManager

        FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
        Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".
    • Method Detail

      • getFlexDirection

         int getFlexDirection()
        Returns:

        the flex direction attribute of the flex container.

      • setFlexDirection

         void setFlexDirection(int flexDirection)

        Sets the given flex direction attribute to the flex container.

        Parameters:
        flexDirection - the flex direction value
      • getFlexWrap

         int getFlexWrap()
        Returns:

        the flex wrap attribute of the flex container.

      • setFlexWrap

         void setFlexWrap(int flexWrap)

        Sets the given flex wrap attribute to the flex container.

        Parameters:
        flexWrap - the flex wrap value
      • getJustifyContent

         int getJustifyContent()
        Returns:

        the justify content attribute of the flex container.

      • setJustifyContent

         void setJustifyContent(int justifyContent)

        Sets the given justify content attribute to the flex container.

        Parameters:
        justifyContent - the justify content value
      • getAlignItems

         int getAlignItems()
        Returns:

        the align items attribute of the flex container.

      • setAlignItems

         void setAlignItems(int alignItems)

        Sets the given align items attribute to the flex container.

        Parameters:
        alignItems - the align items value
      • getAlignContent

         int getAlignContent()
        Returns:

        the align content attribute of the flex container.

      • setAlignContent

         void setAlignContent(int alignContent)

        Sets the given align content attribute to the flex container.

        Parameters:
        alignContent - the align content value
      • getMaxLine

         int getMaxLine()
        Returns:

        the current value of the maximum number of flex lines. If not set, NOT_SET is returned.

      • setMaxLine

         void setMaxLine(int maxLine)
        Parameters:
        maxLine - the int value, which specifies the maximum number of flex lines
      • getFlexLines

         List<FlexLine> getFlexLines()
        Returns:

        the flex lines composing this flex container. The overridden method should return a copy of the original list excluding a dummy flex line (flex line that doesn't have any flex items in it but used for the alignment along the cross axis) so that any changes of the returned list are not reflected to the original list.

      • getDecorationLengthMainAxis

         int getDecorationLengthMainAxis(View view, int index, int indexInFlexLine)

        Returns the length of decoration (such as dividers) of the flex item along the main axis.

        Parameters:
        view - the view from which the length of the decoration is retrieved
        index - the absolute index of the flex item within the flex container
        indexInFlexLine - the relative index of the flex item within the flex line
        Returns:

        the length of the decoration. Note that the length of the flex item itself is not included in the result.

      • getDecorationLengthCrossAxis

         int getDecorationLengthCrossAxis(View view)

        Returns the length of decoration (such as dividers) of the flex item along the cross axis.

        Parameters:
        view - the view from which the length of the decoration is retrieved
        Returns:

        the length of the decoration. Note that the length of the flex item itself is not included in the result.

      • onNewFlexItemAdded

         void onNewFlexItemAdded(View view, int index, int indexInFlexLine, FlexLine flexLine)

        Callback when a new flex item is added to the current container

        Parameters:
        view - the view as a flex item which is added
        index - the absolute index of the flex item added
        indexInFlexLine - the relative index of the flex item added within the flex line
        flexLine - the flex line where the new flex item is added
      • getFlexItemCount

         int getFlexItemCount()
        Returns:

        the number of flex items contained in the flex container. This method doesn't always reflect the latest state of the adapter. If you want to access the latest state of the adapter, use the RecyclerView.State instance passed as an argument for some methods (such as onLayoutChildren) This method is used to avoid the implementation of the similar method. i.e. getChildCount returns the child count, but it doesn't include the children that are detached or scrapped.

      • getFlexItemAt

         View getFlexItemAt(int index)
        Returns:

        the flex item as a view specified as the index. This method doesn't always return the latest state of the view in the adapter. If you want to access the latest state, use the RecyclerView.Recycler instance passed as an argument for some methods (such as onLayoutChildren) This method is used to avoid the implementation of the similar method. i.e. getChildAt returns a view for the given index, but the index is based on the layout position, not based on the adapter position, which isn't desired given the usage of this method.

      • getReorderedFlexItemAt

         View getReorderedFlexItemAt(int index)

        Returns a View for the given index. The order attribute (getOrder) is not supported by this class since otherwise all view holders need to be inflated at least once even though only the visible part of the layout is needed. Implementing this method just to make this class conform to the FlexContainer interface.

        Parameters:
        index - the index of the view
        Returns:

        the view for the given index. If the index is negative or out of bounds of the number of contained views, returns null.

      • onNewFlexLineAdded

         void onNewFlexLineAdded(FlexLine flexLine)

        Callback when a new flex line is added to the current container

        Parameters:
        flexLine - the new added flex line
      • getChildWidthMeasureSpec

         int getChildWidthMeasureSpec(int widthSpec, int padding, int childDimension)

        Returns the child measure spec for its width.

        Parameters:
        widthSpec - the measure spec for the width imposed by the parent
        padding - the padding along the width for the parent
        childDimension - the value of the child dimension
      • getChildHeightMeasureSpec

         int getChildHeightMeasureSpec(int heightSpec, int padding, int childDimension)

        Returns the child measure spec for its height.

        Parameters:
        heightSpec - the measure spec for the height imposed by the parent
        padding - the padding along the height for the parent
        childDimension - the value of the child dimension
      • getLargestMainSize

         int getLargestMainSize()
        Returns:

        the largest main size of all flex lines including decorator lengths.

      • getSumOfCrossSize

         int getSumOfCrossSize()
        Returns:

        the sum of the cross sizes of all flex lines including decorator lengths.

      • setFlexLines

         void setFlexLines(List<FlexLine> flexLines)

        Sets the list of the flex lines that compose the flex container to the one received as an argument.

        Parameters:
        flexLines - the list of flex lines
      • getFlexLinesInternal

         List<FlexLine> getFlexLinesInternal()
        Returns:

        the list of the flex lines including dummy flex lines (flex line that doesn't have any flex items in it but used for the alignment along the cross axis), which aren't included in the getFlexLines.

      • updateViewCache

         void updateViewCache(int position, View view)

        Update the view cache in the flex container.

        Parameters:
        position - the position of the view to be updated
        view - the view instance
      • isMainAxisDirectionHorizontal

         boolean isMainAxisDirectionHorizontal()

        Returns true if the main axis is horizontal, false otherwise.

        Returns:

        true if the main axis is horizontal, false otherwise

      • getRecycleChildrenOnDetach

         boolean getRecycleChildrenOnDetach()
        Returns:

        true if LayoutManager will recycle its children when it is detached from RecyclerView.

      • setRecycleChildrenOnDetach

         void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)

        Set whether this LayoutManager will recycle its children when it is detached from RecyclerView.

        If you are using a RecyclerView.RecycledViewPool, it might be a good idea to set this flag to true so that views will be available to other RecyclerViews immediately.

        Note that, setting this flag will result in a performance drop if RecyclerView is restored.

        Parameters:
        recycleChildrenOnDetach - Whether children should be recycled in detach or not.
      • findFirstVisibleItemPosition

         int findFirstVisibleItemPosition()

        Returns the adapter position of the first visible view. This position does not include adapter changes that were dispatched after the last layout pass. If RecyclerView has item decorators, they will be considered in calculations as well. LayoutManager may pre-cache some views that are not necessarily visible. Those views are ignored in this method.

        Returns:

        The adapter position of the first visible item or NO_POSITION if there aren't any visible items.

      • findFirstCompletelyVisibleItemPosition

         int findFirstCompletelyVisibleItemPosition()

        Returns the adapter position of the first fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.

        Returns:

        The adapter position of the first fully visible item or NO_POSITION if there aren't any visible items.

      • findLastVisibleItemPosition

         int findLastVisibleItemPosition()

        Returns the adapter position of the last visible view. This position does not include adapter changes that were dispatched after the last layout pass. If RecyclerView has item decorators, they will be considered in calculations as well. LayoutManager may pre-cache some views that are not necessarily visible. Those views are ignored in this method.

        Returns:

        The adapter position of the last visible view or NO_POSITION if there aren't any visible items.

      • findLastCompletelyVisibleItemPosition

         int findLastCompletelyVisibleItemPosition()

        Returns the adapter position of the last fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.

        Returns:

        The adapter position of the last fully visible view or NO_POSITION if there aren't any visible items.