[英]Bottom part of NestedScrollView hidden by navigation bar [Android]
我在使用CollapsingToolbarLayout
布局上遇到了NestedScrollView
問題。 當我將文本滾動到底部時,導航欄會覆蓋最后一句。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="Title">
<ImageView
android:id="@+id/toolbar_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/visit_at_office"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lorem_ipsum" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
為TextView添加保證金底部修復了這個錯誤,但我想知道任何更好的解決方案,為什么會發生這種情況。 有人可以幫幫我嗎?
您已經在根布局中添加了android:fitsSystemWindows="true"
,在您的情況下是CoordinatorLayout
。
此行將使視圖適合全屏。
如果有人仍在搜索此問題的解決方案:
問題的原因是CoordinatorLayout沒有正確計算CollapsingToolbarLayout的大小,因為它有工具欄和app:layout_collapseMode="pin"
設置。 它認為CollapsingToolbarLayout將折疊到零高度,因此它將所有可用空間留給NestedScrollView,但實際上發生的是工具欄保持固定,因此NestedScrollView向下移動,在NavigationBar后面。
解決此問題的最簡單方法是將android:minHeight="?attr/actionBarSize"
(或您正在使用的任何工具欄高度)添加到CollapsingToolbarLayout。 這樣,CoordinatorLayout將正確地知道它需要為NestedScrollView留出多少空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.