3

I want to create UI like Google Play Store app. That is to say, it includes these kind of features:

  • DrawerLayout
  • Parallax effect
  • Snapping toolbar that enters when user scrolls up
  • Top image is behind status bar

I have created layout to achieve mentioned features and it works fine except two things:

  1. Toolbar is not snapping when it enters on scrolling up
  2. Parallax effect is not working

Here's my layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/green_dark"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
                app:contentScrim="@color/green_dark"
                app:statusBarScrim="@color/green_dark"
                app:titleEnabled="false">

                <ImageView
                    android:id="@+id/top_app_imageview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.7" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways|snap"
                    app:layout_collapseMode="pin"
                    app:theme="@style/SearchToolbarStyle" />

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:elevation="6dp"
        app:headerLayout="@layout/layout_drawer_header"
        app:menu="@menu/drawer_menu" />

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

Here's how my gradle looks like:

{
...
buildToolsVersion "25.0.0"
...
}

dependencies {
    ....
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
   ....
}

Any ideas why parrallax effect is not working and how to achieve toolbar that snaps?

SpiralDev
  • 7,011
  • 5
  • 28
  • 42

2 Answers2

1
  1. The reason why Parallax effect was not working was that I was setting ImageView's (id: top_app_imageview) width and height programmitcally with setLayoutParams. That somehow interrupted to get correct parallax effect. The workaround was to set width and height of the AppBarLayout programmatically and change Imageview's layout_height to match_parent.
  2. I made the toolbar snapping by changing layout_scrollFlags of the CollapsingToolbarLayout to "scroll|enterAlways|enterAlwaysCollapsed|snap"
SpiralDev
  • 7,011
  • 5
  • 28
  • 42
  • **1.** So you should put these informations in your question before asking... My answer is correct, As you can see here: http://stackoverflow.com/a/35241363/4409113 **2.** Could you just make a video of the output to see what's going on ? – ʍѳђઽ૯ท Dec 29 '16 at 16:42
0

Try this ;

Remove this line in your Toolbar:

app:layout_collapseMode="pin"

And just use this in your Toolbar:

app:layout_scrollFlags="scroll|enterAlways"

So we have :

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways"
    app:theme="@style/SearchToolbarStyle" />
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • Thank you for your answer. But it didn't work! The same result – SpiralDev Dec 26 '16 at 05:16
  • @Umarov Are you trying to get something like this video output? right ? https://sendvid.com/ugjspx8r Taken from : http://stackoverflow.com/questions/32569824/collapsing-toolbar-layout-like-google-play-store Because i did the test and it worked. Please be clear which part didn't worked, By taking a video from output, That would be great. – ʍѳђઽ૯ท Dec 26 '16 at 08:37
  • Thank you for your time. Please, take a look at my answer. – SpiralDev Dec 29 '16 at 16:27