Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make CollapsingToolbarLayout stretching

I used CollapsingToolbarLayout and i need to make it stretching something like this:

enter image description here

this is my layout:

        <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:collapsedTitleGravity="bottom|center_horizontal"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:title="@string/app_name">


            <ImageView
                android:id="@+id/coverIv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            app:layout_collapseMode="pin"

            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

and i need to make the stretching on the imageView. there is any way to do it with CollapsingToolbarLayout? or just with a 3rd party library? I found a way to do it only with 3rd-party (this) but is work with ListView and i have a Recyclerview. but anyway i need to work with android.support.design.widget.CollapsingToolbarLayou.

so there is any chance CollapsingToolbarLayout is supported on something like this? if not, has 3rd party like that are working with actionbar?

Thanks for helping

like image 599
Yoni Avatar asked Sep 11 '17 17:09

Yoni


2 Answers

You need to use the overscroll distance that is travelled by user once the NestedScrollView has reached the top. Then start to expand the CollapsingToolbar for some value and scale the image inside for the same value.

Here in my blog post I did something similar.

like image 76
Nikola Despotoski Avatar answered Oct 20 '22 19:10

Nikola Despotoski


Ive used this library for similar task and it did the trick.

like image 43
Jan Slominski Avatar answered Oct 20 '22 19:10

Jan Slominski