Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toolbar collapseMode issue

I have an Issue making " toolbar with Title text " Not to Collapse while scrolling upwards in CollapsingToolbarLayout.

I have tried a few tweaks, by using app:layout_collapseMode="none" as attribute in my android.support.v7.widget.Toolbar but its not working. Maybe there is a problem with my layout.

Below is what i am trying to achieve.

Trying to Achieve

But when i scroll to the top, the Toolbar also collapse, and the tabBar also scrolls inside, and become non-visible. below is what i have now.

what i have now

This is my Layout Code

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">



        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="250dp"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7">

                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#20000000" />

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="none"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Application Title"
                    android:textColor="#fff"
                    android:textSize="18sp" />
            </android.support.v7.widget.Toolbar>




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



        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/detail_tabs"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                app:layout_collapseMode="pin"

                android:background="#00000000"
                app:tabSelectedTextColor="#3498db"
                app:tabTextColor="#000" />
            />

        </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"
        android:background="#333"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

Dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:22.2.1"
    compile "com.android.support:support-annotations:22.2.1"
    compile "com.android.support:design:22.2.1"
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'

}
like image 303
Tosin Onikute Avatar asked Sep 29 '15 20:09

Tosin Onikute


Video Answer


2 Answers

try this...

You have to use app:layout_scrollFlags="scroll|exitUntilCollapsed" instead of app:layout_scrollFlags="scroll|enterAlways" inside the CollapsingToolbarLayout

and use app:layout_collapseMode="pin" inside the toolbar

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="?attr/colorPrimary" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" >

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#20000000" />
        </FrameLayout>

        <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" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Application Title"
                android:textColor="#fff"
                android:textSize="18sp" />
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>
like image 176
Deepak Goyal Avatar answered Oct 09 '22 22:10

Deepak Goyal


In your toolbar do this:

app:layout_collapseMode="pin"

pin is used for pinning the layout to top when the collapsing toolbar layout scrolls

parallax is used for hiding the layout when collapsing toolbar scrolls to top

like image 30
Aakash Avatar answered Oct 09 '22 21:10

Aakash