问题描述
我是pretty的肯定,这是一个错误,所以我问了一个解决方法。我的布局是这样的:
I'm pretty sure this is a bug, so I'm asking for a workaround. My layout is like:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<android.support.v4.widget.NestedScrollView/> <!-- content here -->
</CoordinatorLayout>
我检索的网页内容,而我不知道有多高这将是 - 可能是几行,可能会很长。然而,我发现, CollapsingToolbar
工作不正常时,内容没有大到足以覆盖整个屏幕。案例:
I'm retrieving content from the web, and I don't know how tall it'll be - might be few lines, might be very long.However, I discovered that CollapsingToolbar
doesn't work well when content is not big enough to cover the entire screen. Cases:
-
content.height&GT; screen.height
:作品;刷卡顶部/底部展开和折叠工具栏,以及滚动的内容;
content.height > screen.height
: works; swiping top/bottom expands and collapses the toolbar, as well as scrolling content;
content.height&LT; screen.height
:没有。这是不可以好,因为大部分的时间(content.height + expandedToolbar.height)的制造&gt; screen.height
!
content.height < screen.height
: doesn't. That's not good, because most of the times (content.height + expandedToolbar.height) > screen.height
!
在换句话说,当含量不够高,即使内容+ expandedToolbar比整个屏幕,它不反应,滚动手势和高得多显示了一些错误 - 它可能需要10比划折叠工具栏一点点。所以,你也很难达到的内容,其中的底部隐藏底部,因为工具栏扩展。
In other words, when content is not tall enough, even if content+expandedToolbar is much taller than the whole screen, it doesn't react to scroll gestures and shows some bugs - it might take ten gestures to collapse the toolbar a little bit. So you can hardly reach the bottom part of the content, which is hidden at the bottom because the toolbar is expanded.
什么解决办法?
如果您想尝试,只取 cheesesquare 样本项目和删除(或减少)在<$ C $内容C> NestedScrollView 在activity_detail.xml [API17这里]
If you want to try, just take the cheesesquare sample project and delete (or reduce) the content inside NestedScrollView
in activity_detail.xml [API17 here]
推荐答案
关键是要增加安卓layout_gravity =fill_vertical
到 NestedScrollView
。通过这种方式,工具栏折叠和展开顺利和放大器;反应滚动手势任何一个非空 NestedScrollView
,不管它的大小。
The trick is to add android:layout_gravity="fill_vertical"
to the NestedScrollView
. This way the toolbar collapses and expands smoothly & reacts to scroll gestures for any non-empty NestedScrollView
, no matter its size.
当然,如果滚动视图是空的,在工具栏不会通过滚动屏幕的内容部分塌陷。但是,这似乎并没有那么糟糕我。
Of course if the scroll view is empty, the toolbar won't collapse by scrolling in the "content" part of the screen. But that doesn't seem so bad to me.
貌似这个解决方案有较大的内容有一些问题,作为内容的最底部部分将被隐藏起来。我能发现隐藏的部分(似乎)一样大的折叠工具栏的高度。这可以很容易地定义一个解决方法 - 只需添加一个保证金的滚动型的底部,以便它能够测量并发布底部,隐藏的部分。因此:
Looks like this solution has some issues with larger contents, as the very bottom part of the content will remain hidden. I could find that the hidden part is (appears to be) as big as the collapsed toolbar height. That makes it easy to define a workaround - just add a margin to the bottom of the ScrollView, so that it gets measured and releases the bottom, hidden part. Thus:
android:layout_gravity="fill_vertical"
android:layout_marginBottom="?attr/actionBarSize"
或任何大小,你给了工具栏
在您的视图。请注意,此解决方案正好符合小型和大型内容,但是滚动是不是与较小的那么顺利。
or whatever size you gave to the Toolbar
in your view. Note that this solution fits well with small and large contents, but scrolling is not so smooth with smaller ones.
从早期的测试中,它看起来是这个bug已经被固定在v22.2.1版本的技术支持设计库中。
From early tests, it looks that this bug has been fixed in the v22.2.1 release of the Support Design Library.
这篇关于CollapsingToolbar不工作不那么高的含量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!