我相信这是一个bug,所以我想要一个解决方法。我的布局如下:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<android.support.v4.widget.NestedScrollView/> <!-- content here -->
</CoordinatorLayout>
我正在从网络检索内容,并且不知道它有多高——可能只有几行,也可能非常长。
然而,我发现当内容不足以覆盖整个屏幕时,CollapsingToolbar
表现不佳。情况如下:
content.height > screen.height
:能够正常工作;向上/向下滑动可以展开和折叠工具栏,并滚动内容;content.height < screen.height
:不能正常工作。这不好,因为大部分情况下(content.height + expandedToolbar.height) > screen.height
!
换句话说,当内容不够高时,即使content+expandedToolbar
的高度比整个屏幕还要高得多,它也无法响应滚动手势并显示一些错误。你可能需要进行十次手势才能稍微折叠工具栏。因此,你几乎无法到达底部的内容,因为工具栏已经展开了并且隐藏了底部的内容。
有什么解决方法吗?
如果您想尝试,请使用cheesesquare示例项目,并删除(或减少)activity_detail.xml中NestedScrollView
内的内容[这里是API17]。