2

i cant get my CoordinatorLayout with a Collapsing Toolbar and a Nested ScrollView to work.

Setting fitssystemwindows="true" on anything else than the CoordinatorLayout has no or negative effects. The App Theme has the attribute

<item name="android:windowTranslucentStatus">true</item>

to make the Status Bar transparent.

My problems are: 1. The Image is scrolling too far down, so that the translucent Status Bar takes the blue Toolbar color (The ImageView is visible, when the Toolbar is not 100% expanded). enter image description here enter image description here

  1. The system's Bottom Bar is hiding part of my NestedScrollView. enter image description here

This is my Layout:

<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="com.example.application.collapsingtoolbarexample.MainActivity">

<android.support.design.widget.AppBarLayout
    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:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/goslings"
            android:scaleType="centerCrop"
            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="match_parent"
    android:background="#dfdddd"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

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

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

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

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

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

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

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

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

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


    </LinearLayout>

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

1 Answers1

0

You need to fit to system windows (everything except toolbar), also setting the height on the image not the CollapsingToolbar

android:fitsSystemWindows="true"

so the final code would be

<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="com.example.application.collapsingtoolbarexample.MainActivity">

<android.support.design.widget.AppBarLayout
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:src="@drawable/goslings"
            android:scaleType="centerCrop"
            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="match_parent"
    android:background="#dfdddd"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

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

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

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

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

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

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

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

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

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


    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Shehabic
  • 6,787
  • 9
  • 52
  • 93