FlowLayout: A Content-Wrapping LinearLayout

Android FlowLayout is a UI component that works like LinearLayout. However, FlowLayout wraps its content whenever we are out of space in a row or column. You can visit the library’s GitHub page via this link: https://github.com/ApmeM/android-flowlayout

Let’s directly dive into how to use this library in our projects:

First, add the following dependency to your module-level “build.gradle” file:

Now, we are ready to use FlowLayout inside our layout XML file as follows:

Here, we basically have five TextView components and set the  orientation of our FlowLayout to  horizontal. As the result, we get the following:

On our phone, there is enough space for the first three TextView components; but after that one, FlowLayout needed to wrap since we are out of screen width. So, it put the fourth and fifth TextView components to the second row.

FlowLayout works also in the same manner when we set its  orientation to  vertical. In that case, when the first column is fully occupied by child components, it puts the rest of its content beginning from the top of the second column.

Leave a Reply

Your email address will not be published. Required fields are marked *