FlexboxLayout
FlexboxLayout is a library project which brings the similar capabilities of CSS Flexible Box Layout Module to Android.
Installation
Add the following dependency to your build.gradle
file:
dependencies {
compile 'com.google.android:flexbox:0.3.0'
}
Usage
There are two ways of using Flexbox in your layout.
FlexboxLayout
The first one is FlexboxLayout
that extends the ViewGroup
like LinearLayout
and RelativeLayout
.
You can specify the attributes from a layout XML like:
Or from code like:
FlexboxLayoutManager (within RecyclerView)
The second one is FlexboxLayoutManager
that can be used within RecyclerView
.
or for the attributes for the children of the FlexboxLayoutManager
you can do like:
The advantage of using FlexboxLayoutManager
is that it recycles the views that go off the screen
for reuse for the views that are appearing as the user scrolls instead of inflating every individual view,
which consumes much less memory especially when the number of items contained in the Flexbox container is large.