androidscrollviewandroid-scrollviewbottom-navigation-baredge-to-edge

ScrollView contents below navigation bar


I'm struggling with the new edge-to-edge display introduced by default with SDK 36. My scroll view contents are behind the navigation bar even when scrolled to the bottom.

I had a look at the "Basic Views" example project which comes with Android Studio, but even there it is not working properly... what the hell?! example project with scroll view content behind navbar

Can you please give me a hint how to avoid that the content hides behind the navbar? I mean adding a <Space> at the bottom of the layout seems not like the intended solution...


Solution

  • Perhaps one way to handle this is to dynamically adjust the bottom padding of your ScrollView (or RecyclerView, or ConstraintLayout) based on the navigation bar's insets.

    Here's a simple Kotlin example using ViewCompat.setOnApplyWindowInsetsListener:

    ViewCompat.setOnApplyWindowInsetsListener(scrollView) { view, insets ->
        val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
        view.setPadding(
            view.paddingLeft,
            view.paddingTop,
            view.paddingRight,
            systemBarsInsets.bottom
        )
        insets
    }
    

    Case do you using XML:

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
        ...
    </ScrollView>