0

I am using CollapsingToolbarLayout with NestedScrollView, and inside the NestedScrollView I have a list of items, but in the execution I can't scroll all of them.

In my example I'm not seeing the last TextView and some of the includes.

This is my activity_main.xml

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="40dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/space"
                app:layout_collapseMode="pin"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:elevation="7dp"/>

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

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

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/ic_search"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right"/>

    <!-- Your Scrollable View : Can be Nested Scroll View or Recycler View-->
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/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"
            android:paddingTop="10dp">

            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <include layout="@layout/item_nested_scrollview"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LastOne"/>

        </LinearLayout>

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

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

And this my list of items.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:elevation="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Smartherd"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp"
            android:textStyle="bold"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="@string/description"
            android:textColor="@android:color/black"
            android:textSize="15sp"/>

    </LinearLayout>

</android.support.v7.widget.CardView>

This photo at the top enter image description here And this one, when I scrolled all down as you can see it's not showing the textview even the cardview is not showing completly. enter image description here

q-l-p
  • 4,304
  • 3
  • 16
  • 36
Aymen
  • 841
  • 1
  • 12
  • 21

2 Answers2

5

I found the answer, I added

android:paddingBottom="?attr/actionBarSize" 

for the Layout inside NestedScrollingView

nutella_eater
  • 3,393
  • 3
  • 27
  • 46
Aymen
  • 841
  • 1
  • 12
  • 21
0

When using CoordinatorLayout and collapsing toolbar you have to define your toolbar as actionbar in java file like that

toolbar=view.findViewById(R.id.toolbar);

if fragment((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);

if activitysetSupportActionBar(toolbar);

And also use in xml of toolbar app:popupTheme="@style/AppTheme.PopupOverlay"

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

also remove any margings or min heights .this solved my problem.