5

I've got a problem with NestedScrollView on layout with CollapsingToolbarLayout. When I scroll text to bottom last sentences are covered by navigation bar.

enter image description here
layout.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@style/ExpandedAppBar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="Title">

            <ImageView
                android:id="@+id/toolbar_image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/visit_at_office"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum" />
    </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>

Adding margin bottom to TextView fixes this bug, but I'd like to know any better solution and why is that happens. Could anyone help me, please?

Sanket Berde
  • 6,555
  • 4
  • 35
  • 39
dudeck
  • 393
  • 5
  • 13

2 Answers2

5

In case anyone is still searching for a solution of this problem:

Cause of the problem is that CoordinatorLayout is not calculating correctly size of CollapsingToolbarLayout because it has Toolbar with app:layout_collapseMode="pin" setting. It thinks that CollapsingToolbarLayout will collapse to zero height so it leaves all available space to NestedScrollView, but actually what happens is that toolbar stays pinned so NestedScrollView moves down, behind NavigationBar.

Easiest way to solve this is just to add android:minHeight="?attr/actionBarSize" (or whatever toolbar height you are using) to CollapsingToolbarLayout. This way CoordinatorLayout will know properly how much space it needs to leave for NestedScrollView.

MarkoR
  • 543
  • 4
  • 12
  • @dudeck I think this is the right answer, and the explanation makes a lot of sense if we consider the types collapmodes – cutiko Dec 12 '19 at 18:06
  • Just got the issue and wanted to say thank you for that answer! Saved me a lot of time! – Benoit Nov 25 '20 at 14:42
0

You have added android:fitsSystemWindows="true" in your root layout, in your case that's CoordinatorLayout.

This line will fit the view to the full screen.

Sanket Berde
  • 6,555
  • 4
  • 35
  • 39