androidandroid-flexboxlayout

How to make FlexboxLayout scroll?


I am using Android FlexboxLayout in one of my Activities, but when the content is larger than my screen, I cannot scroll there to see it. All examples seem to scroll be default, but it just doesn't do that in my code.

The XML is like this:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.flexbox.FlexboxLayout
    android:id="@+id/fbRoot"
    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:alignContent="flex_start"
    app:alignItems="stretch"
    app:flexWrap="wrap">

    .. a lot of other views ..

</com.google.android.flexbox.FlexboxLayout>

Solution

  • Wrap it inside a ScrollView like this

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
    
        <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/fbRoot"
        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:alignContent="flex_start"
        app:alignItems="stretch"
        app:flexWrap="wrap">
    
        .. a lot of other views ..
    
    </com.google.android.flexbox.FlexboxLayout>
    </ScrollView>