5

I have a simple collapsing toolbar inside a fragment, which is inside a viewpager with tablayout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    tools:context=".MainActivity">


     <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:fitsSystemWindows="true"
        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"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginBottom="80dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:background="@color/red">

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>


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

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


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

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

When my fragment first loads it all works fine but when the fragment is reshown after swapping between tabs, I can no longer scroll to the very bottom of the NestedScrollView. The missing section of my content is the same height as the Toolbar (changing the toolbar height changes the missing section height).

Here's the unscrolled view:

enter image description here

When scrolled to the bottom there's a section not shown, in this example there's another 'Text 6' TextView that's off screen and can't be accessed.

enter image description here

On some tabs (I have 6) I can never access the missing section, on others it follows the pattern:

  1. Can scroll to bottom
  2. Change tab and back again
  3. Cannot scroll to bottom
  4. Change multiple tabs so that the fragment is killed
  5. Fragment is re-inflated when selecting tab again
  6. Can scroll to bottom

Any help would be appreciated.

natario
  • 24,954
  • 17
  • 88
  • 158
Leon
  • 3,614
  • 1
  • 33
  • 46
  • Have you tried removing all the fitsSystemWindows out there? – natario Oct 28 '15 at 18:26
  • Also: use app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|exitUntilCollapsed" on your CTL, and remove the scroll flags on your Toolbar. – natario Oct 28 '15 at 18:31
  • I have played with fitsSystemWindows yes, it needs to be set to false because of an issue with a TabBarLayout in the containing view http://stackoverflow.com/questions/33100985/why-does-tablayout-leave-a-gap-for-the-navbar-when-in-immersive-mode – Leon Oct 29 '15 at 08:50
  • The flag changes had no effect unfortunately! – Leon Oct 29 '15 at 08:51
  • Yes, removing is like setting to false. This seems an easy issue, but hard to reproduce. Could you upload your project somewhere? Or at least post your compile dependencies. – natario Oct 29 '15 at 09:10
  • I have left it set to false to ensure I don't mistakenly re-add it to true! I can't upload the project as it's for a client, dependencies of note are support:appcompat-v7:23.1.0, support:support-v4:23.1.0 support:design:23.1.0 gms:play-services:8.1.0 – Leon Oct 29 '15 at 10:12
  • What API level are you testing on? – natario Oct 29 '15 at 10:15
  • API 19, we're making a kiosk app so I'm currently only testing on one device. – Leon Oct 29 '15 at 10:20
  • @Leon Did you solve your problem? – Abhinav Chauhan Nov 23 '19 at 10:01
  • @AbhinavChauhan This was a little while back but I think I didn't find a solution no. – Leon Nov 25 '19 at 09:51

3 Answers3

0

Try these changes. Look at the differences.

<android.support.design.widget.AppBarLayout
    android:layout_height="192dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout

        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:layout_height="?attr/actionBarSize"/>

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


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

    <LinearLayout
        android:layout_height="match_parent">
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
  • Believe it or not that actually made things worse. Adding fitsSystemWindows="true" to the NestedScrollView had no effect but the wrap_content on the CollapsingToolbarLayout increased the size of the cut off area and broke my collapsing toolbar. The toolbar changed colour and the title disappeared from the collapsing toolbar. Thanks for trying though. – Leon Oct 26 '15 at 08:32
0

Did you call setSupportActionBar(your_anim_toolbar)?
Be sure you have this line in your code, and you must add it right after Activity#setContentView (or within Fragment#onCreateView).

Khang .NT
  • 1,504
  • 6
  • 24
  • 46
0

For everyone's reference, since I just had the same problem. This is a known issue and has been fixed in com.google.android.material:material:1.3.0-alpha04

https://github.com/material-components/material-components-android/commit/a21a30026a33fc20cf7ad699d32d1298b84096c6

Also related to Not be able to fully scroll inside a NestedScrollView

Alessandro Mulloni
  • 1,011
  • 1
  • 9
  • 10