Reputation: 7331
I want to create UI like Google Play Store app. That is to say, it includes these kind of features:
I have created layout to achieve mentioned features and it works fine except two things:
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?
Upvotes: 3
Views: 2018
Reputation: 7331
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
. layout_scrollFlags
of the CollapsingToolbarLayout
to "scroll|enterAlways|enterAlwaysCollapsed|snap"
Upvotes: 1
Reputation: 16976
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" />
Upvotes: 0