【发布时间】:2015-12-24 19:28:18
【问题描述】:
我有一个 CoordinatorLayout、AppBarLayout、Toolbar 和 NestedScrollview 形式的主要内容以及里面的东西:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
/>
</android.support.v4.widget.NestedScrollView>
上图中,蓝色部分是 NestedScrollView(即主要内容)。如您所见,它的高度是在不考虑工具栏的情况下计算的,只是移出屏幕。
如果您将 CoordinatorLayout 替换为任何其他布局,则 NestedScrollView 非常适合(同样,蓝色部分是内容,即 NestedScrollView):
它是按设计应有的行为方式吗?如果是这样,如何使 NestedScrollView 完全适合剩余的屏幕而不移动其下方的部分?
更新:如果我删除 NestedScrollView 上的行为,它会移回顶部,但随后会被工具栏覆盖。
更新 2:抱歉,如果不清楚,但使用 CoordinatorLayout 的主要思想是能够应用各种行为,包括提供的默认行为。我有一些用户输入的文本可能不适合屏幕,所以我用 NestedScrollView 包围它。现在,为了方便输入文本并有更多可用空间,我希望工具栏在滚动并输入此输入时滚动出来(因为 adjustPan 和 adjustResize 并不理想)
【问题讨论】:
标签: android android-design-library android-coordinatorlayout