Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollapsingToolbarLayout with tablayout & image as collapsing with sticky toolbar

I want to achieve view similar to below images

Initial view that I need in my app

After user start scrolling view should look like below image

Below are the screens that I have achieved through design support library in android

View i created with mentioned xml When i scroll is hides the tablayout which is not good.

Please see my layout file below

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


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

                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/imageburger"
                    app:layout_collapseMode="parallax" />




                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="50dip"
                    android:layout_below="@+id/toolbar"
                    android:layout_gravity="bottom"
                    android:gravity="bottom"
                    app:layout_collapseMode="pin"
                    app:tabGravity="center"
                    app:tabMode="scrollable" />




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



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



        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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


    <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"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</FrameLayout>

please check the above xml and let me know what I am doing wrong??

like image 744
Pinakin Kansara Avatar asked Aug 03 '15 05:08

Pinakin Kansara


Video Answer


2 Answers

Please check Paul Burke gists, it may be solve your problem,

https://gist.github.com/iPaulPro/1468510f046cb10c51ea

like image 146
Hitesh Dhamshaniya Avatar answered Oct 20 '22 20:10

Hitesh Dhamshaniya


I managed to get it working by this example https://github.com/vitovalov/TabbedCoordinatorLayout.

My code looks like this now:

<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:theme="@style/AppTheme.Trans">
<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="150dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginBottom="60dp"
        app:expandedTitleMarginEnd="64dp">
        <FFImageLoading.Views.ImageViewAsync
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:gravity="top"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            app:titleMarginTop="15dp" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@drawable/gradient"
            app:tabIndicatorHeight="3dp"
            android:layout_gravity="bottom" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

like image 20
Dylan Schoenmakers Avatar answered Oct 20 '22 19:10

Dylan Schoenmakers