AppBarLayout scrolling does not scroll CoordinatorLayout content
-
I have an image inside CollapsingToolbarLayout that is part of the AppBarLayout as shown below. whenever i try to scroll the content by starting scrolling from image it never scrolls. But as soon as I go from recyclerview / NestedScrollView scrolling through the content. Is this the expected behavior of the Layout coordinator? If I want to scroll the content i.eviewview and my recyclerview / NestedScrollView by scrolling the image, how can I achieve this. Am I missing something here?
-
Whenever I try to call recyclerView.smoothScrollBy () / scrollToPosition () / scrollTo () programmatically, it doesn't scroll all ie content of my CoordinatorLayout along with the image.
<>
<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>
<>
source to share
Finally, I have a workaround:
Part 1: I moved ImageView to recyclerview and got parallax effect. I am using https://github.com/kanytu/android-parallax-recyclerview/blob/master/library/src/main/java/com/poliveira/parallaxrecyclerview/ParallaxRecyclerAdapter.java "
Part 2: Since its a RecyclerView I can use recyclerView.smoothScrollBy () / scrollToPosition () / scrollTo ()
source to share