CollapsingToolbarLayout ImageView does not scroll

Using cheesesquare - an example of an Android support library , is it possible to make the ImageView title scroll?

 <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="@dimen/detail_backdrop_height" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp"> <ImageView android:id="@+id/backdrop" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll" app:layout_collapseMode="parallax" /> ... </android.support.design.widget.CollapsingToolbarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" app:layout_behavior="@string/appbar_scrolling_view_behavior"> .... 

Please note that I added the added android:fillViewport="true" to the NestedScrollView , and also added the app:layout_scrollFlags="scroll" to the ImageView , but nothing happens when I try to scroll from the ImageView .

+7
android android-scrollview android-support-library android-design-library collapsingtoolbarlayout
source share
3 answers

OK, I did some research in bug reports, and this is a known bug in the Design Support Library .

See bug report here

Excerpt

I reviewed an implementation that supports the CoordinatorLayout / AppBarLayout / Behavior classes, etc. AppBarLayout by default uses the behavior defined in AppBarLayout.Behavior . This extends ViewOffsetBehavior , which in turn extends Behavior . The Behavior base class has onInterceptTouchEvent() and onTouchEvent() methods, both of which return false (which means "we donโ€™t want to handle touch events"). These methods are not overridden by either ViewOffsetBehavior or AppBarLayout.Behavior , which means that the touch remains unprocessed - which is why it does nothing.

A possible workaround for third-party developers would be the extension AppBarLayout.Behavior and the implementation of onInterceptTouchEvent() and onTouchEvent() and, accordingly, control of the application panel.

Video

They show current and alleged behavior. This is also from the bug report.

+4
source share

I found a workaround by inserting imageView into NestedScrollView:

  <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:id="@+id/appbar" android:background="@color/transparent" android:layout_width="match_parent"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/transparent" app:toolbarId="@+id/toolbar" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_collapseMode="parallax" app:layout_scrollFlags="scroll" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <ImageView tools:ignore="UnusedAttribute" tools:src="@drawable/placeholder" android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:adjustViewBounds="true" android:scaleType="centerCrop" android:minHeight="200dp"/> </android.support.v4.widget.NestedScrollView> <android.support.v7.widget.Toolbar android:layout_height="?attr/actionBarSize" android:id="@+id/toolbar" android:elevation="0dp" android:layout_width="match_parent" app:layout_collapseMode="pin"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> 

But I did not test it in prod, as I encountered another problem with the transition to the upper gesture, which is interrupted when the recyclerview reaches the top (as explained in the error report).

+2
source share

From testing this in the support library 23.1.1, this problem seems to be fixed.

 compile 'com.android.support:design:23.1.1' 

Now you can add anything to your CollapsingToolbarLayout, ImageView, RelativeLayout, TextView and scroll them as you like.

0
source share

All Articles