Package 

Class FlexboxLayoutManager

  • All Implemented Interfaces:
    android.support.v7.widget.RecyclerView.SmoothScroller.ScrollVectorProvider , com.pointrlabs.core.util.flexbox.FlexContainer

    
    public class FlexboxLayoutManager
    extends RecyclerView.LayoutManager implements FlexContainer, RecyclerView.SmoothScroller.ScrollVectorProvider
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class FlexboxLayoutManager.LayoutParams

      LayoutParams used by the FlexboxLayoutManager, which stores per-child information required for the Flexbox. Note that some parent fields (which are not primitive nor a class implements Parcelable) are not included as the stored/restored fields after this class is serialized/de-serialized as an Parcelable.

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      FlexboxLayoutManager(Context context) Creates a default FlexboxLayoutManager.
      FlexboxLayoutManager(Context context, int flexDirection) Creates a FlexboxLayoutManager with the flexDirection specified.
      FlexboxLayoutManager(Context context, int flexDirection, int flexWrap) Creates a FlexboxLayoutManager with the flexDirection and flexWrap attributes specified.
      FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getFlexDirection()
      void setFlexDirection(int flexDirection) Sets the given flex direction attribute to the flex container.
      int getFlexWrap()
      void setFlexWrap(int flexWrap) Sets the given flex wrap attribute to the flex container.
      int getJustifyContent()
      void setJustifyContent(int justifyContent) Sets the given justify content attribute to the flex container.
      int getAlignItems()
      void setAlignItems(int alignItems) Sets the given align items attribute to the flex container.
      int getAlignContent()
      void setAlignContent(int alignContent) Sets the given align content attribute to the flex container.
      int getMaxLine()
      void setMaxLine(int maxLine)
      List<FlexLine> getFlexLines()
      int getDecorationLengthMainAxis(View view, int index, int indexInFlexLine) Returns the length of decoration (such as dividers) of the flex item along the main axis.
      int getDecorationLengthCrossAxis(View view) Returns the length of decoration (such as dividers) of the flex item along the cross axis.
      void onNewFlexItemAdded(View view, int index, int indexInFlexLine, FlexLine flexLine) Callback when a new flex item is added to the current container
      int getFlexItemCount()
      View getFlexItemAt(int index)
      View getReorderedFlexItemAt(int index) Returns a View for the given index.
      void onNewFlexLineAdded(FlexLine flexLine) Callback when a new flex line is added to the current container
      int getChildWidthMeasureSpec(int widthSpec, int padding, int childDimension) Returns the child measure spec for its width.
      int getChildHeightMeasureSpec(int heightSpec, int padding, int childDimension) Returns the child measure spec for its height.
      int getLargestMainSize()
      int getSumOfCrossSize()
      void setFlexLines(List<FlexLine> flexLines) Sets the list of the flex lines that compose the flex container to the one received as an argument.
      List<FlexLine> getFlexLinesInternal()
      void updateViewCache(int position, View view) Update the view cache in the flex container.
      PointF computeScrollVectorForPosition(int targetPosition)
      RecyclerView.LayoutParams generateDefaultLayoutParams()
      RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs)
      boolean checkLayoutParams(RecyclerView.LayoutParams lp)
      void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter)
      Parcelable onSaveInstanceState()
      void onRestoreInstanceState(Parcelable state)
      void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)
      void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)
      void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)
      void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)
      void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)
      void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
      void onLayoutCompleted(RecyclerView.State state)
      boolean isMainAxisDirectionHorizontal() Returns true if the main axis is horizontal, false otherwise.
      void scrollToPosition(int position)
      void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)
      boolean getRecycleChildrenOnDetach()
      void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach) Set whether this LayoutManager will recycle its children when it is detached from RecyclerView.
      void onAttachedToWindow(RecyclerView recyclerView)
      void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)
      boolean canScrollHorizontally()
      boolean canScrollVertically()
      int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)
      int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
      int computeHorizontalScrollExtent(RecyclerView.State state)
      int computeVerticalScrollExtent(RecyclerView.State state)
      int computeHorizontalScrollOffset(RecyclerView.State state)
      int computeVerticalScrollOffset(RecyclerView.State state)
      int computeHorizontalScrollRange(RecyclerView.State state)
      int computeVerticalScrollRange(RecyclerView.State state)
      int findFirstVisibleItemPosition() Returns the adapter position of the first visible view.
      int findFirstCompletelyVisibleItemPosition() Returns the adapter position of the first fully visible view.
      int findLastVisibleItemPosition() Returns the adapter position of the last visible view.
      int findLastCompletelyVisibleItemPosition() Returns the adapter position of the last fully visible view.
      • Methods inherited from class android.support.v7.widget.RecyclerView.LayoutManager

        addDisappearingView, addView, assertInLayoutOrScroll, assertNotInLayoutOrScroll, attachView, calculateItemDecorationsForChild, chooseSize, collectAdjacentPrefetchPositions, collectInitialPrefetchPositions, detachAndScrapAttachedViews, detachAndScrapView, detachAndScrapViewAt, detachView, detachViewAt, endAnimation, findContainingItemView, findViewByPosition, generateLayoutParams, getBaseline, getBottomDecorationHeight, getChildAt, getChildCount, getChildMeasureSpec, getClipToPadding, getColumnCountForAccessibility, getDecoratedBottom, getDecoratedBoundsWithMargins, getDecoratedLeft, getDecoratedMeasuredHeight, getDecoratedMeasuredWidth, getDecoratedRight, getDecoratedTop, getFocusedChild, getHeight, getHeightMode, getItemCount, getItemViewType, getLayoutDirection, getLeftDecorationWidth, getMinimumHeight, getMinimumWidth, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPosition, getProperties, getRightDecorationWidth, getRowCountForAccessibility, getSelectionModeForAccessibility, getTopDecorationHeight, getTransformedBoundingBox, getWidth, getWidthMode, hasFocus, ignoreView, isAttachedToWindow, isAutoMeasureEnabled, isFocused, isItemPrefetchEnabled, isLayoutHierarchical, isMeasurementCacheEnabled, isSmoothScrolling, isViewPartiallyVisible, layoutDecorated, layoutDecoratedWithMargins, measureChild, measureChildWithMargins, moveView, offsetChildrenHorizontal, offsetChildrenVertical, onAddFocusables, onDetachedFromWindow, onFocusSearchFailed, onInitializeAccessibilityEvent, onInterceptFocusSearch, onItemsChanged, onMeasure, onRequestChildFocus, onScrollStateChanged, postOnAnimation, removeAllViews, removeAndRecycleAllViews, removeAndRecycleView, removeAndRecycleViewAt, removeCallbacks, removeDetachedView, removeView, removeViewAt, requestChildRectangleOnScreen, requestLayout, requestSimpleAnimationsInNextLayout, setAutoMeasureEnabled, setItemPrefetchEnabled, setMeasuredDimension, setMeasurementCacheEnabled, startSmoothScroll, stopIgnoringView, supportsPredictiveItemAnimations
      • Methods inherited from class com.pointrlabs.core.util.flexbox.FlexContainer

        addView, addView, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, removeAllViews, removeViewAt
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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

      • setFlexDirection

         void setFlexDirection(int flexDirection)

        Sets the given flex direction attribute to the flex container.

        Parameters:
        flexDirection - the flex direction value
      • setFlexWrap

         void setFlexWrap(int flexWrap)

        Sets the given flex wrap attribute to the flex container.

        Parameters:
        flexWrap - the flex wrap value
      • setJustifyContent

         void setJustifyContent(int justifyContent)

        Sets the given justify content attribute to the flex container.

        Parameters:
        justifyContent - the justify content value
      • setAlignItems

         void setAlignItems(int alignItems)

        Sets the given align items attribute to the flex container.

        Parameters:
        alignItems - the align items value
      • setAlignContent

         void setAlignContent(int alignContent)

        Sets the given align content attribute to the flex container.

        Parameters:
        alignContent - the align content value
      • setMaxLine

         void setMaxLine(int maxLine)
        Parameters:
        maxLine - the int value, which specifies the maximum number of flex lines
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • onAdapterChanged

         void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter)
      • onItemsAdded

         void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)
      • onItemsUpdated

         void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)
      • onItemsUpdated

         void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)
      • onItemsRemoved

         void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)
      • onItemsMoved

         void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)
      • onLayoutChildren

         void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
      • smoothScrollToPosition

         void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)
      • 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.
      • onDetachedFromWindow

         void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)
      • scrollHorizontallyBy

         int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)
      • scrollVerticallyBy

         int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
      • 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.

      • 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.

      • 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.

      • 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.