<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"> ....
请注意,我已经添加了添加android:fillViewport =“true”到NestedScrollView并添加了app:layout_scrollFlags =“scroll”to
ImageView但是当试图从ImageView滚动时没有任何反应.
解决方法
摘抄
I have taken a look at the implementation that backs
CoordinatorLayout
/AppBarLayout
/theBehavior
classes etc. TheAppBarLayout
uses the behavIoUr defined inAppBarLayout.Behavior
by default. This extendsViewOffsetBehavior
which in turn extendsBehavior
. The baseBehavior
class has the methodsonInterceptTouchEvent()
andonTouchEvent()
,both of which return false (meaning “we don’t want to handle touch events”). These methods are not overridden by eitherViewOffsetBehavior
orAppBarLayout.Behavior
,meaning that the touch is left unhandled – which is why it does nothing.A possible workaround for third-party developers would be to extend
AppBarLayout.Behavior
and implementonInterceptTouchEvent()
andonTouchEvent()
and manipulate the app bar accordingly.
影片
> https://youtu.be/xWadOVEaTSY
> https://youtu.be/J8ITp6RusZo