### Complete FlexboxLayout XML Example Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/configuration.md A comprehensive example demonstrating the setup of a FlexboxLayout with various attributes for controlling direction, wrapping, justification, and alignment. It also includes child TextViews with specific layout parameters. ```xml ``` -------------------------------- ### XML Setup for FlexboxLayout Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/README.md Demonstrates how to set up FlexboxLayout in XML with common properties like flexDirection, flexWrap, and justifyContent. Includes an example of a TextView with flexGrow. ```xml ``` -------------------------------- ### Basic FlexboxLayout Setup with XML Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Demonstrates the basic XML setup for a FlexboxLayout, including wrap behavior and content justification. ```xml ``` -------------------------------- ### Install Flexbox Playground Demo App Source: https://github.com/google/flexbox-layout/blob/main/README.md Use this command to install the demo app for experimenting with FlexboxLayout attributes. This app allows trying various attribute values. ```bash ./gradlew demo-playground:installDebug ``` -------------------------------- ### Basic FlexboxLayoutManager Setup Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Demonstrates the basic setup of a FlexboxLayoutManager for a RecyclerView, including setting direction, wrap behavior, and alignment. ```java RecyclerView recyclerView = findViewById(R.id.recycler_view); FlexboxLayoutManager manager = new FlexboxLayoutManager(context); manager.setFlexDirection(FlexDirection.ROW); manager.setFlexWrap(FlexWrap.WRAP); manager.setJustifyContent(JustifyContent.FLEX_START); manager.setAlignItems(AlignItems.STRETCH); recyclerView.setLayoutManager(manager); recyclerView.setAdapter(myAdapter); ``` -------------------------------- ### Install Cat Gallery Demo App Source: https://github.com/google/flexbox-layout/blob/main/README.md Install the demo app that showcases FlexboxLayoutManager within RecyclerView for efficient image handling. This is useful for memory-intensive applications. ```bash ./gradlew demo-cat-gallery:installDebug ``` -------------------------------- ### Wrap Before Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Methods to get and set whether an item forces a flex line wrap. Useful for starting a new line before this item. ```java public boolean isWrapBefore() public void setWrapBefore(boolean wrapBefore) ``` -------------------------------- ### FlexBasisPercent Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Methods to get and set the initial flex item length as a fraction of the parent's size. Used to define the starting size before growing or shrinking. ```java public float getFlexBasisPercent() public void setFlexBasisPercent(float flexBasisPercent) ``` -------------------------------- ### Complete FlexboxLayoutManager XML Example Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/configuration.md An example of setting up a RecyclerView to use FlexboxLayoutManager. This XML defines the RecyclerView and specifies FlexboxLayoutManager as its layout manager, along with basic orientation. ```xml ``` -------------------------------- ### Set Horizontal Divider Example Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Demonstrates setting a horizontal divider drawable and enabling its display. ```java flexboxLayout.setDividerDrawableHorizontal(context.getDrawable(R.drawable.divider)); flexboxLayout.setShowDividerHorizontal(FlexboxLayout.SHOW_DIVIDER_MIDDLE); ``` -------------------------------- ### Java Setup for FlexboxLayout Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/README.md Shows how to programmatically configure FlexboxLayout properties in Java, such as flexDirection, flexWrap, justifyContent, and alignItems. ```java FlexboxLayout flexbox = findViewById(R.id.flexbox); flexbox.setFlexDirection(FlexDirection.ROW); flexbox.setFlexWrap(FlexWrap.WRAP); flexbox.setJustifyContent(JustifyContent.CENTER); flexbox.setAlignItems(AlignItems.CENTER); ``` -------------------------------- ### DividerMode Usage Example Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Shows how to set the divider display mode for FlexboxLayout by combining different divider constants. ```java flexboxLayout.setShowDivider(SHOW_DIVIDER_BEGINNING | SHOW_DIVIDER_MIDDLE); ``` -------------------------------- ### FlexLine Usage Example Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Demonstrates how to retrieve and use properties of a FlexLine object, such as its main size and the count of visible items. ```java List lines = flexboxLayout.getFlexLines(); for (FlexLine line : lines) { int mainSize = line.getMainSize(); int items = line.getItemCountNotGone(); } ``` -------------------------------- ### Basic FlexboxLayoutManager Setup with Item Decoration Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxItemDecoration.md Sets up a RecyclerView with a FlexboxLayoutManager and adds a FlexboxItemDecoration using the default theme divider. ```java RecyclerView recyclerView = findViewById(R.id.recyclerview); FlexboxLayoutManager manager = new FlexboxLayoutManager(context); recyclerView.setLayoutManager(manager); FlexboxItemDecoration decoration = new FlexboxItemDecoration(context); recyclerView.addItemDecoration(decoration); ``` -------------------------------- ### Configuring Item Layout Parameters Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Example of how to configure FlexboxLayoutManager.LayoutParams within a RecyclerView Adapter's onBindViewHolder to control item growth and shrinkage. ```java // In your RecyclerView.Adapter's onBindViewHolder public void onBindViewHolder(MyViewHolder holder, int position) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp instanceof FlexboxLayoutManager.LayoutParams) { FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp; flexboxLp.setFlexGrow(1.0f); flexboxLp.setFlexShrink(1.0f); holder.itemView.setLayoutParams(flexboxLp); } } ``` -------------------------------- ### Flex Wrap Property Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Methods for getting and setting the flex wrap behavior of the container. ```APIDOC ## getFlexWrap() ### Description Returns the flex wrap attribute of the flex container. ### Method GET ### Endpoint /flexContainer/flexWrap ### Returns - **@FlexWrap int** - One of NOWRAP, WRAP, or WRAP_REVERSE ``` ```APIDOC ## setFlexWrap(@FlexWrap int flexWrap) ### Description Sets the flex wrap attribute. Determines whether flex items wrap to multiple lines when they don't fit on the main axis. ### Method PUT ### Endpoint /flexContainer/flexWrap ### Parameters #### Request Body - **flexWrap** (@FlexWrap int) - Required - One of NOWRAP, WRAP, or WRAP_REVERSE ``` -------------------------------- ### LayoutParams Property Methods Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Methods for getting and setting layout properties for items managed by FlexboxLayoutManager. ```APIDOC ## getFlexGrow() / setFlexGrow(float) ### Description Gets/sets how much the item will grow if positive free space is distributed. ### Parameters #### Path Parameters - **flexGrow** (float) - Required ### Returns - **float** - The flex grow factor ``` ```APIDOC ## getFlexShrink() / setFlexShrink(float) ### Description Gets/sets how much the item will shrink if negative free space is distributed. ### Parameters #### Path Parameters - **flexShrink** (float) - Required ### Returns - **float** - The flex shrink factor ``` ```APIDOC ## getAlignSelf() / setAlignSelf(int) ### Description Gets/sets the alignment along the cross axis for this item. ### Parameters #### Path Parameters - **alignSelf** (int) - Required - Annotated with @AlignSelf ### Returns - **int** - The alignment value ``` ```APIDOC ## getFlexBasisPercent() / setFlexBasisPercent(float) ### Description Gets/sets the initial flex item length as a fraction of parent. ### Parameters #### Path Parameters - **flexBasisPercent** (float) - Required ### Returns - **float** - The flex basis percentage ``` ```APIDOC ## getMinWidth() / setMinWidth(int), getMinHeight() / setMinHeight(int) ### Description Gets/sets the minimum width and height constraints. ### Parameters #### Path Parameters - **minWidth** (int) - Required - **minHeight** (int) - Required ### Returns - **int** - The minimum dimension in pixels ``` ```APIDOC ## getMaxWidth() / setMaxWidth(int), getMaxHeight() / setMaxHeight(int) ### Description Gets/sets the maximum width and height constraints. ### Parameters #### Path Parameters - **maxWidth** (int) - Required - **maxHeight** (int) - Required ### Returns - **int** - The maximum dimension in pixels ``` ```APIDOC ## isWrapBefore() / setWrapBefore(boolean) ### Description Gets/sets whether this item forces a flex line wrap. ### Parameters #### Path Parameters - **wrapBefore** (boolean) - Required ### Returns - **boolean** - True if the item forces a wrap, false otherwise ``` -------------------------------- ### RecyclerView with FlexboxLayoutManager Setup Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/README.md Illustrates how to integrate FlexboxLayoutManager with a RecyclerView in Java, including setting layout direction and wrap behavior. ```java RecyclerView recyclerView = findViewById(R.id.recyclerview); FlexboxLayoutManager manager = new FlexboxLayoutManager(context); manager.setFlexDirection(FlexDirection.ROW); manager.setFlexWrap(FlexWrap.WRAP); recyclerView.setLayoutManager(manager); recyclerView.setAdapter(adapter); ``` -------------------------------- ### Setup RecyclerView with FlexboxLayoutManager and FlexboxItemDecoration Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxItemDecoration.md This snippet shows how to initialize a RecyclerView with FlexboxLayoutManager and apply FlexboxItemDecoration for visual dividers. Ensure you have the necessary context and adapter. ```java RecyclerView recyclerView = findViewById(R.id.recyclerview); FlexboxLayoutManager manager = new FlexboxLayoutManager(context, FlexDirection.ROW); manager.setFlexWrap(FlexWrap.WRAP); recyclerView.setLayoutManager(manager); // Add item decoration FlexboxItemDecoration decoration = new FlexboxItemDecoration(context); decoration.setDrawable(context.getDrawable(R.drawable.divider)); decoration.setOrientation(FlexboxItemDecoration.BOTH); recyclerView.addItemDecoration(decoration); // Set adapter recyclerView.setAdapter(myAdapter); ``` -------------------------------- ### Set and Get Flex Wrap Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Shows how to configure the flex container's wrapping behavior and retrieve the current wrap setting. Note that WRAP_REVERSE is not supported in FlexboxLayoutManager. ```java flexboxLayout.setFlexWrap(FlexWrap.WRAP); int wrap = container.getFlexWrap(); ``` -------------------------------- ### Get/Set Minimum Width/Height Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets or sets the minimum width and height constraints for a flex item. ```Java public int getMinWidth() public void setMinWidth(int minWidth) public int getMinHeight() public void setMinHeight(int minHeight) ``` -------------------------------- ### Min/Max Width and Height Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Methods to get and set the minimum and maximum width and height constraints for a flex item. Ensures items do not become too small or too large. ```java public int getMinWidth() public void setMinWidth(int minWidth) public int getMinHeight() public void setMinHeight(int minHeight) ``` ```java public int getMaxWidth() public void setMaxWidth(int maxWidth) public int getMaxHeight() public void setMaxHeight(int maxHeight) ``` -------------------------------- ### FlexGrow and FlexShrink Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Methods to get and set the flex grow and shrink factors for an item. Controls how items resize in response to available space. ```java public float getFlexGrow() public void setFlexGrow(float flexGrow) ``` ```java public float getFlexShrink() public void setFlexShrink(float flexShrink) ``` -------------------------------- ### Alignment Properties Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Methods for getting and setting alignment properties for flex items and lines. ```APIDOC ## Justify Content (Main Axis) ### Description Gets/sets the alignment of flex items along the main axis. ### Method GET/PUT ### Endpoint /flexContainer/justifyContent ### Parameters #### Request Body (for PUT) - **justifyContent** (@JustifyContent int) - Required - One of FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY ### Returns (for GET) - **@JustifyContent int** - The current justification value ``` ```APIDOC ## Align Items (Cross Axis) ### Description Gets/sets the alignment of flex items along the cross axis. ### Method GET/PUT ### Endpoint /flexContainer/alignItems ### Parameters #### Request Body (for PUT) - **alignItems** (@AlignItems int) - Required - One of FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH ### Returns (for GET) - **@AlignItems int** - The current alignment value ``` ```APIDOC ## Align Content (Flex Lines) ### Description Gets/sets the alignment of flex lines. Only applies when flexWrap is not NOWRAP. ### Method GET/PUT ### Endpoint /flexContainer/alignContent ### Parameters #### Request Body (for PUT) - **alignContent** (@AlignContent int) - Required - One of FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, STRETCH ### Returns (for GET) - **@AlignContent int** - The current alignment value ``` -------------------------------- ### Query Layout Results from Flexbox Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/INDEX.md Retrieve layout information such as main and cross sizes, and item counts from Flexbox by getting the list of FlexLines. ```java List lines = flexbox.getFlexLines(); for (FlexLine line : lines) { int mainSize = line.getMainSize(); int crossSize = line.getCrossSize(); int itemCount = line.getItemCountNotGone(); } ``` -------------------------------- ### Set Flex Container Properties Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Provides examples for setting various flex container properties such as flex direction, flex wrap, justify content, align items, and align content. These methods control the layout and alignment of children within the FlexboxLayout. ```java public void setFlexDirection(@FlexDirection int flexDirection) ``` ```java public void setFlexWrap(@FlexWrap int flexWrap) ``` ```java public void setJustifyContent(@JustifyContent int justifyContent) ``` ```java public void setAlignItems(@AlignItems int alignItems) ``` ```java public void setAlignContent(@AlignContent int alignContent) ``` -------------------------------- ### Get/Set Maximum Width/Height Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets or sets the maximum width and height constraints for a flex item. ```Java public int getMaxWidth() public void setMaxWidth(int maxWidth) public int getMaxHeight() public void setMaxHeight(int maxHeight) ``` -------------------------------- ### Set and Get Align Items Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Demonstrates setting the alignment of flex items along the cross axis and retrieving the current alignment. This affects how items are positioned perpendicular to the main axis. ```java flexboxLayout.setAlignItems(AlignItems.CENTER); int align = container.getAlignItems(); ``` -------------------------------- ### FlexboxLayout Class Reference Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/MANIFEST.md Documentation for the FlexboxLayout class, detailing its constructors, flex container methods, item access methods, divider methods, line management methods, and constants. It also covers the LayoutParams inner class and provides usage examples. ```APIDOC ## Class FlexboxLayout ### Description Provides a flexible layout implementation for Android that mimics the CSS Flexible Box Layout module. ### Constructors - **FlexboxLayout()**: Default constructor. - **FlexboxLayout(Context context)**: Constructor with context. - **FlexboxLayout(Context context, AttributeSet attrs)**: Constructor with context and attributes. ### Methods #### Flex Container Methods (12) - **setFlexDirection(int flexDirection)**: Sets the direction of the flex container. - **setFlexWrap(int flexWrap)**: Sets the wrapping behavior of the flex container. - **setJustifyContent(int justifyContent)**: Sets the alignment of flex items along the main axis. - **setAlignItems(int alignItems)**: Sets the alignment of flex items along the cross axis. - **setAlignContent(int alignContent)**: Sets the alignment of flex lines within the flex container. - **setShowDivider(int showDivider)**: Sets the visibility of dividers. - **setShowDividerVertical(int showDividerVertical)**: Sets the visibility of vertical dividers. - **setShowDividerHorizontal(int showDividerHorizontal)**: Sets the visibility of horizontal dividers. - **setDividerDrawable(Drawable dividerDrawable)**: Sets the drawable for dividers. - **setDividerDrawableHorizontal(Drawable dividerDrawableHorizontal)**: Sets the drawable for horizontal dividers. - **setDividerDrawableVertical(Drawable dividerDrawableVertical)**: Sets the drawable for vertical dividers. - **setFlexFontScale(float flexFontScale)**: Sets the scale factor for flex font. #### Item Access Methods (8) - **getItemCount()**: Returns the number of flex items. - **getFlexItemAt(int index)**: Returns the flex item at the specified index. - **indexOfChild(View child)**: Returns the index of the specified child view. #### Divider Methods (8) - **getShowDivider()**: Gets the current divider visibility setting. - **getShowDividerVertical()**: Gets the current vertical divider visibility setting. - **getShowDividerHorizontal()**: Gets the current horizontal divider visibility setting. - **getDividerDrawable()**: Gets the current divider drawable. - **getDividerDrawableHorizontal()**: Gets the horizontal divider drawable. - **getDividerDrawableVertical()**: Gets the vertical divider drawable. #### Line Management Methods (5) - **getFlexLineCount()**: Returns the number of flex lines. - **getFlexLineAt(int index)**: Returns the flex line at the specified index. - **getFlexLines()**: Returns a list of all flex lines. #### Divider Mode Constants (4) - **SHOW_DIVIDER_NONE**: No dividers are shown. - **SHOW_DIVIDER_BEGINNING**: Dividers are shown at the beginning. - **SHOW_DIVIDER_MIDDLE**: Dividers are shown in the middle. - **SHOW_DIVIDER_END**: Dividers are shown at the end. ### LayoutParams Inner Class #### Properties (19) - **flexGrow**: Controls how much a flex item will grow. - **flexShrink**: Controls how much a flex item will shrink. - **flexBasisPercent**: Sets the initial main size of a flex item. - **alignSelf**: Overrides the container's align-items property for a specific item. - **order**: Controls the order in which flex items appear. - **wrapBefore**: Determines if the item should start on a new line. - **leftMargin**, **topMargin**, **rightMargin**, **bottomMargin**: Margins for the item. - **marginStart**, **marginEnd**: Start and end margins. - **marginLeft**, **marginTop**, **marginRight**, **marginBottom**: Specific margins. - **marginStartPercent**, **marginEndPercent**: Percentage-based start and end margins. - **flexBasis**: Sets the initial main size of a flex item. ### Usage Examples - Example 1: Basic Flexbox Layout setup. - Example 2: Using FlexboxLayout with custom attributes. - Example 3: Advanced layout with item ordering and alignment. ``` -------------------------------- ### LayoutParams.getFlexBasisPercent / LayoutParams.setFlexBasisPercent Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets the initial flex basis percentage for a flex item. This defines the initial size of the flex item before any growing or shrinking occurs, expressed as a fraction of the parent container's size. The default is -1 (not set). ```APIDOC ## getFlexBasisPercent() / setFlexBasisPercent(float) ### Description Gets/sets the initial flex item length as a fraction of parent (default: -1, not set). ### Method ```java public float getFlexBasisPercent() public void setFlexBasisPercent(float flexBasisPercent) ``` ### Parameters #### Path Parameters - **flexBasisPercent** (float) - Required - The flex basis percentage ``` -------------------------------- ### Setup with Custom Drawable and Both Orientations Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxItemDecoration.md Configures a RecyclerView with a custom drawable for item decoration and sets the orientation to draw dividers in both horizontal and vertical directions. ```java FlexboxItemDecoration decoration = new FlexboxItemDecoration(context); Drawable customDivider = context.getDrawable(R.drawable.my_divider); decoration.setDrawable(customDivider); decoration.setOrientation(FlexboxItemDecoration.BOTH); recyclerView.addItemDecoration(decoration); ``` -------------------------------- ### Set and Get Justify Content Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Illustrates how to set the justification of flex items within the container and retrieve the current justification setting. This controls spacing and alignment along the main axis. ```java flexboxLayout.setJustifyContent(JustifyContent.CENTER); int align = container.getJustifyContent(); ``` -------------------------------- ### LayoutParams.getMinWidth / LayoutParams.setMinWidth, LayoutParams.getMinHeight / LayoutParams.setMinHeight Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets the minimum width and height constraints for a flex item. These values ensure that the flex item does not shrink below the specified dimensions, regardless of available space. ```APIDOC ## getMinWidth() / setMinWidth(int), getMinHeight() / setMinHeight(int) ### Description Gets/sets the minimum width and height constraints. ### Method ```java public int getMinWidth() public void setMinWidth(int minWidth) public int getMinHeight() public void setMinHeight(int minHeight) ``` ### Parameters #### Path Parameters - **minWidth** (int) - Required - The minimum width constraint - **minHeight** (int) - Required - The minimum height constraint ``` -------------------------------- ### Get Align Content Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Returns the current align content attribute, which controls the alignment of flex lines. The default value is FLEX_START. ```java @AlignContent public int getAlignContent() ``` -------------------------------- ### Get Flex Wrap Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the current flex wrap behavior of the container. This dictates whether items should wrap to new lines. ```java @FlexWrap int getFlexWrap() ``` -------------------------------- ### FlexboxLayout with Dividers Source: https://github.com/google/flexbox-layout/blob/main/README.md Configures a FlexboxLayout with horizontal and vertical dividers. This example demonstrates setting the divider drawable and specifying which dividers to show (beginning and middle). ```xml ``` -------------------------------- ### Simple Divider Drawable Resource Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxItemDecoration.md Define a basic drawable resource for item dividers in `res/drawable/divider.xml`. This example creates a 1dp by 1dp solid gray line. ```xml ``` -------------------------------- ### Adding Dividers to Flexbox Layouts Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/README.md Provides code examples for adding dividers to both standalone FlexboxLayout and RecyclerViews using FlexboxLayoutManager. It shows how to set the divider drawable and visibility. ```java // FlexboxLayout (built-in) flexbox.setDividerDrawable(context.getDrawable(R.drawable.divider)); flexbox.setShowDivider(FlexboxLayout.SHOW_DIVIDER_MIDDLE); // FlexboxLayoutManager (via ItemDecoration) FlexboxItemDecoration decoration = new FlexboxItemDecoration(context); decoration.setDrawable(context.getDrawable(R.drawable.divider)); recyclerView.addItemDecoration(decoration); ``` -------------------------------- ### Set and Get Flex Direction Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/types.md Demonstrates how to set the flex direction on a FlexboxLayout and retrieve the current direction. This is useful for controlling the primary layout axis. ```java flexboxLayout.setFlexDirection(FlexDirection.ROW); int direction = container.getFlexDirection(); ``` -------------------------------- ### Add FlexboxLayout Dependency Source: https://github.com/google/flexbox-layout/blob/main/README.md Add this dependency to your build.gradle file for installation. Starting from 3.0.0, the groupId is changed to `com.google.android.flexbox`. ```gradle dependencies { implementation 'com.google.android.flexbox:flexbox:3.0.0' } ``` -------------------------------- ### getPaddingTop, getPaddingLeft, getPaddingRight, getPaddingBottom, getPaddingStart, getPaddingEnd Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the padding values for the top, left, right, bottom, start, and end edges of the flex container, used in layout calculations. ```APIDOC ## Padding Access Methods ### Description These methods retrieve the padding values for the flex container's edges, which are essential for accurate layout calculations. ### Methods - **getPaddingTop()**: Returns the top padding value in pixels. - **getPaddingLeft()**: Returns the left padding value in pixels. - **getPaddingRight()**: Returns the right padding value in pixels. - **getPaddingBottom()**: Returns the bottom padding value in pixels. - **getPaddingStart()**: Returns the start padding value in pixels. - **getPaddingEnd()**: Returns the end padding value in pixels. ### Returns int - Padding value in pixels for the respective edge. ``` -------------------------------- ### Setting Up FlexboxLayout Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/INDEX.md Initialize FlexboxLayout and set its core properties like direction, wrap, and justification. ```java FlexboxLayout flexbox = new FlexboxLayout(context); flexbox.setFlexDirection(FlexDirection.ROW); flexbox.setFlexWrap(FlexWrap.WRAP); flexbox.setJustifyContent(JustifyContent.CENTER); ``` -------------------------------- ### LayoutParams.getMaxWidth / LayoutParams.setMaxWidth, LayoutParams.getMaxHeight / LayoutParams.setMaxHeight Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets the maximum width and height constraints for a flex item. These values prevent the flex item from growing beyond the specified dimensions, even if there is ample free space. ```APIDOC ## getMaxWidth() / setMaxWidth(int), getMaxHeight() / setMaxHeight(int) ### Description Gets/sets the maximum width and height constraints. ### Method ```java public int getMaxWidth() public void setMaxWidth(int maxWidth) public int getMaxHeight() public void setMaxHeight(int maxHeight) ``` ### Parameters #### Path Parameters - **maxWidth** (int) - Required - The maximum width constraint - **maxHeight** (int) - Required - The maximum height constraint ``` -------------------------------- ### Get Padding Values Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the padding values for the top, left, right, bottom, start, and end edges of the flex container. These values are used in layout calculations and are in pixels. ```java int getPaddingTop() int getPaddingLeft() int getPaddingRight() int getPaddingBottom() int getPaddingStart() int getPaddingEnd() ``` -------------------------------- ### Create and Configure FlexboxLayout Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Demonstrates how to create a new FlexboxLayout instance and set its flex direction and wrap behavior. This is useful for initializing a flex container with specific layout properties. ```java FlexboxLayout flexboxLayout = new FlexboxLayout(context); flexboxLayout.setFlexDirection(FlexDirection.ROW); flexboxLayout.setFlexWrap(FlexWrap.WRAP); ``` -------------------------------- ### Get Flex Container Properties Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Shows how to retrieve the current flex container properties including flex direction, flex wrap, justify content, align items, and align content. These getter methods are useful for inspecting the current layout state of the FlexboxLayout. ```java @FlexDirection public int getFlexDirection() ``` ```java @FlexWrap public int getFlexWrap() ``` ```java @JustifyContent public int getJustifyContent() ``` ```java @AlignItems public int getAlignItems() ``` ```java @AlignContent public int getAlignContent() ``` -------------------------------- ### Fluid Grid Layout with FlexboxLayout Source: https://github.com/google/flexbox-layout/wiki/Target-use-cases This XML layout defines a FlexboxLayout that wraps its children and aligns them to the start. It's used to create a fluid grid where TextViews can grow and shrink, maintaining ratios and dynamically adjusting the number of items per row. ```xml ``` -------------------------------- ### Retrieve FlexLines with FlexboxLayoutManager Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexLine.md Get all FlexLines from a FlexboxLayoutManager associated with a RecyclerView. ```java RecyclerView recyclerView = findViewById(R.id.recyclerview); FlexboxLayoutManager manager = (FlexboxLayoutManager) recyclerView.getLayoutManager(); List flexLines = manager.getFlexLines(); for (FlexLine line : flexLines) { int visibleItems = line.getItemCountNotGone(); int totalGrow = (int) line.getTotalFlexGrow(); Log.d("FlexLine", "Visible: " + visibleItems + ", TotalGrow: " + totalGrow); } ``` -------------------------------- ### Project File Structure Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/MANIFEST.md Overview of the directory structure for the FlexboxLayout project, including the location of the main documentation files and the API reference. ```text /workspace/home/output/ ├── README.md # Main entry point (11 KB) ├── INDEX.md # Navigation guide (13 KB) ├── QUICK_REFERENCE.md # Quick reference (10 KB) ├── types.md # Type definitions (14 KB) ├── configuration.md # XML & parameters (14 KB) ├── MANIFEST.md # This file └── api-reference/ # Class documentation (60 KB) ├── FlexboxLayout.md # Main class (16 KB) ├── FlexboxLayoutManager.md # Layout manager (15 KB) ├── FlexboxItemDecoration.md # Decorations (7.6 KB) ├── FlexLine.md # Flex lines (7.4 KB) └── FlexContainer.md # Interface (12 KB) Total: 192 KB, 4,096 lines ``` -------------------------------- ### LayoutParams.getFlexShrink / LayoutParams.setFlexShrink Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets the flex shrink factor for a flex item. This determines how much a flex item will shrink relative to other flex items when there is negative free space in the flex container. The default value is 1. ```APIDOC ## getFlexShrink() / setFlexShrink(float) ### Description Gets/sets how much the child will shrink if negative free space is distributed (default: 1). ### Method ```java public float getFlexShrink() public void setFlexShrink(float flexShrink) ``` ### Parameters #### Path Parameters - **flexShrink** (float) - Required - The flex shrink factor ``` -------------------------------- ### Get Internal Flex Lines Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the current list of flex lines, including dummy lines used for internal calculations. This method is primarily for internal use by the layout algorithm. ```java List getFlexLinesInternal() ``` -------------------------------- ### Setup for Horizontal Dividers Only Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxItemDecoration.md Configures a RecyclerView to use FlexboxItemDecoration with only horizontal dividers. ```java FlexboxItemDecoration decoration = new FlexboxItemDecoration(context); decoration.setOrientation(FlexboxItemDecoration.HORIZONTAL); recyclerView.addItemDecoration(decoration); ``` -------------------------------- ### LayoutParams.getFlexGrow / LayoutParams.setFlexGrow Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets the flex grow factor for a flex item. This determines how much a flex item will grow relative to other flex items when there is positive free space in the flex container. The default value is 0. ```APIDOC ## getFlexGrow() / setFlexGrow(float) ### Description Gets/sets how much the child will grow if positive free space is distributed (default: 0). ### Method ```java public float getFlexGrow() public void setFlexGrow(float flexGrow) ``` ### Parameters #### Path Parameters - **flexGrow** (float) - Required - The flex grow factor ``` -------------------------------- ### FlexboxLayout Constructors Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Provides documentation for the different constructors of the FlexboxLayout class, used for initializing the layout with default or specified attributes. ```APIDOC ## FlexboxLayout(Context) ### Description Creates a FlexboxLayout with default attributes. ### Method Signature `public FlexboxLayout(Context context)` ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the view is running in ### Response #### Success Response - **FlexboxLayout** - An instance of FlexboxLayout. ## FlexboxLayout(Context, AttributeSet) ### Description Creates a FlexboxLayout with the specified context and attributes. ### Method Signature `public FlexboxLayout(Context context, AttributeSet attrs)` ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the view is running in - **attrs** (AttributeSet) - Required - The attributes of the XML tag that is inflating the view ### Response #### Success Response - **FlexboxLayout** - An instance of FlexboxLayout. ## FlexboxLayout(Context, AttributeSet, int) ### Description Creates a FlexboxLayout with context, attributes, and default style attribute. ### Method Signature `public FlexboxLayout(Context context, AttributeSet attrs, int defStyleAttr)` ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the view is running in - **attrs** (AttributeSet) - Required - The attributes of the XML tag that is inflating the view - **defStyleAttr** (int) - Required - An attribute in the current theme that contains a reference to a style resource ### Response #### Success Response - **FlexboxLayout** - An instance of FlexboxLayout. ### Example ```java FlexboxLayout flexboxLayout = new FlexboxLayout(context); flexboxLayout.setFlexDirection(FlexDirection.ROW); flexboxLayout.setFlexWrap(FlexWrap.WRAP); ``` ``` -------------------------------- ### Flex Direction Property Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Methods for getting and setting the flex direction of the container. ```APIDOC ## getFlexDirection() ### Description Returns the flex direction attribute of the flex container. ### Method GET ### Endpoint /flexContainer/flexDirection ### Returns - **@FlexDirection int** - One of ROW, ROW_REVERSE, COLUMN, or COLUMN_REVERSE ``` ```APIDOC ## setFlexDirection(@FlexDirection int flexDirection) ### Description Sets the flex direction attribute. The flex direction determines which axis is the main axis and the direction of flow. ### Method PUT ### Endpoint /flexContainer/flexDirection ### Parameters #### Request Body - **flexDirection** (@FlexDirection int) - Required - One of ROW, ROW_REVERSE, COLUMN, or COLUMN_REVERSE ``` -------------------------------- ### LayoutParams.isWrapBefore / LayoutParams.setWrapBefore Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Gets and sets a boolean value indicating whether a flex item should force a new flex line to begin before it. This is useful for controlling line breaks within the flex container. The default value is false. ```APIDOC ## isWrapBefore() / setWrapBefore(boolean) ### Description Gets/sets whether this item forces a flex line wrap (default: false). ### Method ```java public boolean isWrapBefore() public void setWrapBefore(boolean wrapBefore) ``` ### Parameters #### Path Parameters - **wrapBefore** (boolean) - Required - True to force a wrap before this item, false otherwise ``` -------------------------------- ### Get Horizontal Divider Mode Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves the current mode for displaying horizontal dividers. ```java public int getShowDividerHorizontal() ``` -------------------------------- ### Get Vertical Divider Mode Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves the current mode for displaying vertical dividers. ```java public int getShowDividerVertical() ``` -------------------------------- ### LayoutParams Constructor (width, height) Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Constructor for creating LayoutParams with specified width and height. ```Java public LayoutParams(int width, int height) ``` -------------------------------- ### Get Vertical Divider Drawable Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves the drawable used for vertical dividers between flex items. ```java public Drawable getDividerDrawableVertical() ``` -------------------------------- ### Get Horizontal Divider Drawable Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves the drawable used for horizontal dividers between flex lines. ```java public Drawable getDividerDrawableHorizontal() ``` -------------------------------- ### Core Query Methods Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Methods for querying the number of flex items and accessing individual flex items. ```APIDOC ## getFlexItemCount() ### Description Returns the number of flex items contained in the flex container. ### Method GET ### Endpoint /flexContainer/itemCount ### Returns - **int** - Total number of children/items ``` ```APIDOC ## getFlexItemAt(int index) ### Description Returns a flex item (child view) at the given index. ### Method GET ### Endpoint /flexContainer/itemAt/{index} ### Parameters #### Path Parameters - **index** (int) - Required - The index of the child ### Returns - **View** - The child view at the specified index ``` ```APIDOC ## getReorderedFlexItemAt(int index) ### Description Returns a flex item reordered by taking the order attribute into account. This method returns items in the laid-out order. ### Method GET ### Endpoint /flexContainer/reorderedItemAt/{index} ### Parameters #### Path Parameters - **index** (int) - Required - The index of the view ### Returns - **View** - The reordered view, or null if index is negative or out of bounds ``` -------------------------------- ### Get Reordered Child View Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves a child view, considering the 'order' attribute for its position. ```java public View getReorderedChildAt(int index) ``` -------------------------------- ### Get Flex Item Margins Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayout.md Retrieves the margin values (left, top, right, bottom) for a flex item. ```Java public int getMarginLeft() public int getMarginTop() public int getMarginRight() public int getMarginBottom() ``` -------------------------------- ### Distribute space equally in FlexboxLayout Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/QUICK_REFERENCE.md Make items distribute space equally by setting `layout_flexGrow` and `layout_flexShrink` to 1, and `layout_width` to `0dp`. ```xml ``` -------------------------------- ### Get Align Content Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the alignment of flex lines within the container. This property is only effective when flexWrap is not NOWRAP. ```java @AlignContent int getAlignContent() ``` -------------------------------- ### getFlexLines Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Returns a list of flex lines that compose the layout. ```APIDOC ## getFlexLines() ### Description Returns a list of flex lines that compose the layout. ### Method public List getFlexLines() ### Returns List - A copy of the flex lines list ``` -------------------------------- ### Get Flex Direction Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexContainer.md Retrieves the current flex direction of the container. This determines the main axis for item flow. ```java @FlexDirection int getFlexDirection() ``` -------------------------------- ### Iterate Through Items in a FlexLine Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexLine.md Get a specific FlexLine and iterate through its items using the first index and item count. ```java FlexLine flexLine = flexLines.get(lineIndex); int firstIndex = flexLine.getFirstIndex(); int itemCount = flexLine.getItemCount(); for (int i = 0; i < itemCount; i++) { int childIndex = firstIndex + i; View child = flexboxLayout.getFlexItemAt(childIndex); // Process child } ``` -------------------------------- ### getFlexItemAt Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Retrieves a flex item at a specific index. ```APIDOC ## getFlexItemAt(int) ### Description Returns the flex item at the given index. ### Method public View getFlexItemAt(int index) ### Parameters #### Path Parameters - **index** (int) - Required - The index of the item ### Returns View - The child view at the index, or null if not found ``` -------------------------------- ### FlexboxLayoutManager Constructors Source: https://github.com/google/flexbox-layout/blob/main/_autodocs/api-reference/FlexboxLayoutManager.md Provides constructors for initializing FlexboxLayoutManager with different configurations, including default settings, specified flex direction, and XML attributes. ```APIDOC ## FlexboxLayoutManager(Context) ### Description Creates a default FlexboxLayoutManager with ROW direction and WRAP mode. ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the layout manager is running in ### Request Example ```java RecyclerView recyclerView = findViewById(R.id.recyclerview); FlexboxLayoutManager manager = new FlexboxLayoutManager(context); recyclerView.setLayoutManager(manager); ``` ## FlexboxLayoutManager(Context, int) ### Description Creates a FlexboxLayoutManager with specified flex direction. ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the layout manager is running in - **flexDirection** (@FlexDirection int) - Required - One of ROW, ROW_REVERSE, COLUMN, or COLUMN_REVERSE ## FlexboxLayoutManager(Context, int, int) ### Description Creates a FlexboxLayoutManager with specified flex direction and wrap mode. ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the layout manager is running in - **flexDirection** (@FlexDirection int) - Required - One of ROW, ROW_REVERSE, COLUMN, or COLUMN_REVERSE - **flexWrap** (@FlexWrap int) - Required - One of NOWRAP or WRAP (WRAP_REVERSE not supported) ## FlexboxLayoutManager(Context, AttributeSet, int, int) ### Description Constructor for use when layout manager is set in XML via RecyclerView attribute. Maps LinearLayoutManager attributes to Flexbox attributes: `android:orientation` maps to `FlexDirection` (HORIZONTAL → ROW, VERTICAL → COLUMN), `reverseLayout` reverses the direction (ROW → ROW_REVERSE, COLUMN → COLUMN_REVERSE). ### Parameters #### Path Parameters - **context** (Context) - Required - The Context the layout manager is running in - **attrs** (AttributeSet) - Required - The attributes from XML - **defStyleAttr** (int) - Required - Default style attribute - **defStyleRes** (int) - Required - Default style resource ```