【发布时间】:2015-12-24 23:52:05
【问题描述】:
标题很清楚。我有这个布局:
_________________
|_______________| <- Toolbar
|___|___|___|___| <- Tablayout
| |
| |
| ViewPager |
| |
|_______________|
工具栏和标签布局都在AppBarLayout 内,所以我可以使用滚动标志来隐藏工具栏滚动到顶部。问题是这只适用于支持嵌套滚动的视图。大多数标签——我的意思是,大部分页面——都是support.v4.NestedScrollViews,所以没关系;其他人是(并且需要)ListViews。
从 Lollipop 开始,我只需将 android:nestedScrollingEnabled="true" 添加到列表视图中,工具栏就会在滚动时正确隐藏。
但是,在 APICoordinatorLayout 中的一些测量错误,列表中的最后一项被隐藏了:listview 的行为就像它拥有工具栏当前占用的空间。
解决方案:
切换到
RecyclerView,它确实支持嵌套滚动:我不能,因为我需要使用仅适用于适配器视图且无法替换的外部库适配器(即@ 987654328@);扩展
ListView并实现嵌套滚动:看起来有点复杂;扩展
ListView并实施一些解决方法,例如测量内容以避免最后一项问题或(和)自定义行为以使工具栏隐藏:看起来也很复杂;使用一些布局技巧:找不到。
有什么帮助吗?
例如,我(拼命地)尝试过:
<android.support.v4.widget.NestedScrollView
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.v4.widget.NestedScrollView>
但是这样ListView 不会被布置为match_parent。我得到一个小高度的小视图,页面的其余部分是空的。
【问题讨论】:
标签: android android-listview android-support-library android-design-library android-appbarlayout