There's nothing in the standard Android framework that will let you do this, but there is a very nice external library from Google called FlexboxLayout that will do it for you.
You'd use a FlexboxLayout
as the parent for all of your TextView
s instead of e.g. a LinearLayout
, and it will take care of wrapping them for you.
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flexWrap="wrap">
<!-- add your 20 textviews here -->
</com.google.android.flexbox.FlexboxLayout>
Note that it's important to specify app:flexWrap="wrap"
because the default is to not do wrapping. I'm not sure why that is, since the whole point of using this library is to get wrapping, but hey.