3

I made an activity where image should collapse with toolbar and only text below would be visible. But When Toolbar being collapsed, there shows up a large gap between Toolbar and NestedScrollView

<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        app:elevation="5dp"
        app:layout_collapseMode="pin"
        android:fitsSystemWindows="true"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:toolbarId="@+id/toolbar"
            android:id="@+id/collapsing"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <com.noframe.farmisagronom.util.ResizibleImageView
                android:id="@+id/image_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
                android:minHeight="100dp"
                android:maxHeight="400dp"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5"
                android:scaleType="centerCrop"/>

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

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nesteview"
        app:layout_anchorGravity="top"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
         .....
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

And this activity looks really good. enter image description here

But when i scroll up the NestedScrollView this goes out of control. enter image description here

This little space between toolbar and text is getting on my nerves.

note that if there is large text in NestedScrollView problem won't show up, but if NestedScrollView + collapsed tool bar doesn't take all phone screen, then there is a gap between them.

Alpha
  • 1,754
  • 3
  • 21
  • 39

1 Answers1

7

Adding:

android:layout_gravity="fill_vertical"

to the NestedScrollView worked for me.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
venturidoo
  • 393
  • 1
  • 9
  • What does this do exactly? – IgorGanapolsky Jul 09 '15 at 19:00
  • It forces the NestedScrollView to fill its container (The CoordinatorLayout) vertically while CollapsingToolbar collapses. – venturidoo Jul 10 '15 at 09:59
  • 1
    Strange that there's no attribute layout_gravity for NestedScrollView but if you put it anyway it is not refused and it works... However after this issue you have the problem of the scrolling if views, inside it, are clickable. For this check question: http://stackoverflow.com/questions/31136740/scroll-doesnt-work-in-nestedscrollview-when-try-to-scroll-from-views-with-click – Davideas Jul 13 '15 at 15:42
  • @Davidea NestedScrollView extends `FrameLayout` which extends `ViewGroup` which extends `View`. All these superclasses have their attributes – Louis CAD Dec 15 '15 at 17:30
  • Failed to work for me. Although I have a nested CoordinatorLayout Inside another one, with BottomSheet behavior. The BottomSheet contains the app bar. The issue only arises when the BottomSheet is opened by default and the screen is on when the app is launched. If the screen is locked and the app is launched, there is no issue. – McP Mar 15 '16 at 09:42