Search code examples
androidxmlandroid-fragmentsbottomnavigationview

Problems with BottomNavigation and Scrollview in Fragment


So I want to create an app with a Bottom Navigation Bar and a Fragment containing a Scrollview hosting some Cardviews. Now the problem is that no matter what I try I can't get the Scrollview to scroll. I have already tried to use a Nestedscrollview and even switched to a Recyclerview both of which had the same issue of not being scrollable.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/bottom_navigation_selector"
        app:itemTextColor="@drawable/bottom_navigation_text_selector"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:navGraph="@navigation/mobile_navigation"
        tools:layout_editor_absoluteX="0dp" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="58dp"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

fragment_home.xml:

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:fillViewport="false"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

            <include layout="@layout/card_polaroid_1" />

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

            <include layout="@layout/card_polaroid_2" />


        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

            <include layout="@layout/card_polaroid_3" />

        </androidx.cardview.widget.CardView>
    </LinearLayout>


</androidx.core.widget.NestedScrollView> 

I'm actually quite confused as of course there are a lot of apps using a Bottom Navigation Bar in combination with Fragments containing Scrollviews and still I'm not able to find this issue mentioned anywhere. Probably I'm missing something obvious. Thanks in advance for answers!


Solution

  • Well turns out it was an unnecessary Listview (the last one in activity_main.xml) I thought was standard for the Bottom Navigation Template and I still don't know how it ended up there. It was basically blocking everything scrollable on the Fragments. Took me some hours to figure this out yikes.