CollapsingToolbarLayout ImageView的不可滚动 [英] CollapsingToolbarLayout ImageView is not scrollable
问题描述
使用 cheesesquare - 支持Android库的例子是有可能使页眉 ImageView的
滚动能?
Using cheesesquare - android support library example is it possible to make the Header ImageView
scroll-able?
<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">
....
的通知,我已经增加添加安卓fillViewport =真正的
到 NestedScrollView
也添加 应用程序:layout_scrollFlags =滚动
来
在的ImageView
而是试图从的ImageView
没有滚动的时候发生。
Notice that i've added added android:fillViewport="true"
to NestedScrollView
and also added app:layout_scrollFlags="scroll"
to
the ImageView
but when trying to scroll from the ImageView
nothing happens.
推荐答案
OK,我做了一些研究,在错误报告,和这是设计支持库中的一个已知的bug
OK, I did some research in the bug reports, and this is a known bug within the Design Support Library
.
<一个href="https://$c$c.google.com/p/android/issues/detail?id=176673&q=collapsingToolbarLayout%20scroll&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars"相对=nofollow>此处退房的bug报告
我已经采取了看看那个备份 CoordinatorLayout
/ AppBarLayout
/的的实施行为
类等。 AppBarLayout
默认使用的 AppBarLayout.Behavior
定义的行为。这延伸 ViewOffsetBehavior
从而延长行为
。该基地行为
类有方法 onInterceptTouchEvent()
和的onTouchEvent()
,这两者返回false(意思是我们不想处理触摸事件)。这些方法不受任何覆盖 ViewOffsetBehavior
或 AppBarLayout.Behavior
,这意味着触摸是左未处理 - 这就是为什么它什么都不做。
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.
一个可能的解决方法为第三方开发者将延长 AppBarLayout.Behavior
和实施 onInterceptTouchEvent()
和的onTouchEvent()
并相应地操纵应用栏。
A possible workaround for third-party developers would be to extend AppBarLayout.Behavior
and implement onInterceptTouchEvent()
and onTouchEvent()
and manipulate the app bar accordingly.
这些显示当前和预期的行为。这也可以从错误报告。
Videos
These show the current and intended behavior. These are also from the bug report.
- https://youtu.be/xWadOVEaTSY
- https://youtu.be/J8ITp6RusZo
这篇关于CollapsingToolbarLayout ImageView的不可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!