3

I am using CoordinatorLayout, AppBarLayout and CollapsingToolbarLayout. I have set layout_scrollFlags="scroll|enterAlwaysCollapsed". In NestedScrollView, I have LinearLayout which height vary based on TextView Content size.

Problem: When I have big content in TextView say 100 lines then my toolbar collapsed as expected but if I have say 2-3 lines in the TextView then toolbar still collapsed where as my page does not scroll.

Help: Please help in fixing this page so that if my page has enough scrollable content then only toolbar should be collapsed otherwise it should not collapse.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    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:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            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"
            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="fill_parent"

    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Info"
            android:textAppearance="@style/TextAppearance.AppCompat.Title" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/cheese_ipsum" />

    </LinearLayout>


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

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Kapil
  • 1,790
  • 1
  • 16
  • 32
  • Aditya, could you please eleborate your objective. You want the AppBar to be collapsed even if the content of NestedScrollView is small and fits the screen height? – DmitryArc Oct 19 '15 at 10:05
  • Thanks for commenting!! If page content is more then only appbar should collapse. OR you can say "As much page is scrollable due to content that much appbar should collapse" – Kapil Oct 19 '15 at 17:44
  • it looks like you a [similar problem](http://stackoverflow.com/questions/32288179/prevent-collapsingtoolbarlayout-collapse-if-not-needed/33217312#33217312). So maybe the proposed solution will be useful for you – DmitryArc Oct 20 '15 at 10:30

0 Answers0