Reputation: 422
I have a imageview inside a CollapsingToolbarLayout which is part of AppBarLayout as shown below. whenever I try to scroll the content by starting the scroll from the imageview It never scrolls, But the moment I scroll from the recyclerview/NestedScrollView it scroll the content. Was this the expected behavior of CoordinatorLayout ? If I want to scroll the content i.e imageview and my recyclerview/NestedScrollView by scrolling the imageview how I can achieve this. Am I missing something here ?
Whenever I try to call recyclerView.smoothScrollBy()/scrollToPosition()/scrollTo() programatically it doesn't scroll the entire content i.e my CoordinatorLayout along with imageview.
<>
<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:id="@+id/appToolbarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
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:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/header"
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_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView // or NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<>
Upvotes: 3
Views: 1951
Reputation: 422
Finally I have a workaround:
Part 1 : I moved the ImageView to the recyclerview and to have the parallax effect I am using the "https://github.com/kanytu/android-parallax-recyclerview/blob/master/library/src/main/java/com/poliveira/parallaxrecyclerview/ParallaxRecyclerAdapter.java"
Part 2 : As its a RecyclerView i can use recyclerView.smoothScrollBy()/scrollToPosition()/scrollTo()
Upvotes: 1