-1

I have a layout containing Navigation drawer, toolbar and bottom sheet. The RecyclerView is also present in the layout which does not scroll.

Root layout is CoordinatorLayout which encapsulates -> i) DrawerLayout & ii) NestedScrollView (For bottom sheet behavior)

DrawerLayout encapsulates -> i) LinearLayout & ii) NavigationView

LinearLayout encapsulates -> i) Toolbar ii) ConstraintLayout

ConstraintLayout encapsulates -> i) ViewPager ii) TextView iii) RecyclerView (This does not scroll)

Below is my xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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="match_parent"
    android:fitsSystemWindows="true"
    tools:context="e.a.exlorista_customer.MainActivity">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorActionBarBackground"
                android:elevation="4dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v4.view.ViewPager
                    android:id="@+id/imgSliderVP"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/nearByStoresTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Nearby Stores"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    app:layout_constraintTop_toBottomOf="@+id/imgSliderVP"
                    app:layout_constraintStart_toStartOf="parent"
                    android:layout_marginStart="10dp"
                    android:layout_marginLeft="10dp"/>

                <android.support.v7.widget.RecyclerView
                    <!-- This does not scroll -->
                    android:id="@+id/storeRV"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginLeft="10dp"
                    app:layout_constraintTop_toBottomOf="@+id/nearByStoresTV" />

            </android.support.constraint.ConstraintLayout>

        </LinearLayout>

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/cartSummary_MainActivityNSV"
        android:layout_width="match_parent"
        android:layout_height="65sp"
        android:clipToPadding="true"
        android:background="@color/colorActionBarBackground"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <LinearLayout
            android:id="@+id/cartSummary_MainActivityLL"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp">
            <TextView
                android:id="@+id/cartItemCount_MainActivityTV"
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:layout_weight="0.4"
                android:textColor="@color/colorActionBarTitleText"
                android:textStyle="bold"
                android:textSize="20sp"
                android:gravity="center_vertical"
                android:text="1 item"/>
            <Button
                android:id="@+id/proceedToCart_MainActivityB"
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:layout_weight="0.6"
                android:text="Proceed to cart"/>
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

What I've tried :

  1. Encapsulated ConstraintLayout inside NestedScrollView
  2. Encapsulated RecyclerView inside NestedScrollView

Neither 1 nor 2 worked.

I'm new in Android so please bear with my naivety If this question involves any.

1 Answers1

0

ConstraintLayout encapsulates -> i) ViewPager ii) TextView iii) RecyclerView (This does not scroll)

Of course it won't.

CoordinatorLayout should be a direct child of DrawerLayout. Also if you're using CoordinatorLayout and NestedScrollView, you may have to add AppBarLayout inside the CoordinatorLayout.

Example layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ui.MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:elevation="0dp">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:overScrollMode="never"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:titleEnabled="false">

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/myToolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/AppTheme" />

            </com.google.android.material.appbar.CollapsingToolbarLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <!-- Your nestedScrollview here which should have this attribute 
            app:layout_behavior="@string/appbar_scrolling_view_behavior" /> -->

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_view_header"
        app:menu="@menu/main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

Please read the documentations first. Also, nowadays you can use AndroidX namespace. You can migrate now.

ʍѳђઽ૯ท
  • 15,369
  • 7
  • 47
  • 103
  • Thanks for pointing out that CoordinatorLayout should be a direct child of DrawerLayout. Probably, this was the first right thing that I needed to do. However, setting the attribute app:layout_behavior="@string/appbar_scrolling_view_behavior" for the NestedScrollView was not what I wanted, as it was supposed to be the bottom sheet so the layout_behavior attribute had to be app:layout_behavior="android.support.design.widget.BottomSheetBehavior". Also, I didn't had to use AppBarLayout and the constraintLayout had to be encapsulated in another NestedScrollView. – shashank kushwaha Jul 09 '20 at 18:02
  • By setting the attribute `app:layout_behavior="@string/appbar_scrolling_view_behavior"` to the `NestedScrollView`, I meant use this attribute for the content you're trying to scroll under the `AppBarLayout`. And also, this is the common way of achieving the scrolling behaviors by using `app:layout_behavior="@string/appbar_scrolling_view_behavior"` in the `NestedScrollView`, perhaps you should take some ideas from how it works with the `NestedScrollView` & the `CoordinatorLayout` – ʍѳђઽ૯ท Jul 09 '20 at 18:07