【发布时间】:2017-10-16 15:33:12
【问题描述】:
默认情况下,当用户从NestedScrollView 滚动视图时,CollapsingToolbarLayout 会被折叠或展开。
如何关闭自动展开?我想要实现的是一个工具栏,我只能通过调用AppBarLayout::setExpanded 来展开或折叠它。
【问题讨论】:
标签: android material-design android-collapsingtoolbarlayout
默认情况下,当用户从NestedScrollView 滚动视图时,CollapsingToolbarLayout 会被折叠或展开。
如何关闭自动展开?我想要实现的是一个工具栏,我只能通过调用AppBarLayout::setExpanded 来展开或折叠它。
【问题讨论】:
标签: android material-design android-collapsingtoolbarlayout
好的,我找到了答案。为了使工具栏在滚动的屏幕上折叠,我们必须创建以下布局层次结构:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Toolbar />
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView>
<!-- content -->
</NestedScrollView>
</CoordinatorLayout>
为了关闭此功能(使滚动不会导致工具栏折叠),我们只需将NestedScrollView 替换为ScrollView。
【讨论】: