为什么我的内容显示在我的应用栏下方?
Why my content is showing below my Appbar?
我正在尝试添加一个 AppBarLayout,当不需要滚动(或内容尚未滚动)时,高度为 0,但当用户可以滚动或已经滚动时,高度为显示(如 Google Tasks 应用程序)。在 new material Appbar documentation 中,我发现将 app:liftOnScroll="true"
属性 添加到我的 Appbar 就可以了,但是在添加我的 NestedScrollView 的内容显示在工具栏上方之后:
我面临的另一个问题是,即使我不使用 app:liftOnScroll="true"
,我的 NestedScrollView 也没有显示在 Appbar 的底部:
这是我的片段 xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:context=".ResetPasswordFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar_resetPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView_resetPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Some Content -->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
我知道,如果我将 layout_marginTop="?attr/actionBarSize"
添加到我的 NestedScrollView 中,问题就会得到解决,但我已经看到很多示例,他们创建了我想要的视图而不添加它。
这是我为 activity
使用的样式
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:statusBarColor">#fff</item>
<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/barlow</item>
</style>
提前致谢!
appbar_scrolling_view_behavior
与 CordinatorLayout
一起使用。因此,如果 ConstraintLayout
..
,则需要使用 CordinatorLayout
作为父项
我正在尝试添加一个 AppBarLayout,当不需要滚动(或内容尚未滚动)时,高度为 0,但当用户可以滚动或已经滚动时,高度为显示(如 Google Tasks 应用程序)。在 new material Appbar documentation 中,我发现将 app:liftOnScroll="true"
属性 添加到我的 Appbar 就可以了,但是在添加我的 NestedScrollView 的内容显示在工具栏上方之后:
我面临的另一个问题是,即使我不使用 app:liftOnScroll="true"
,我的 NestedScrollView 也没有显示在 Appbar 的底部:
这是我的片段 xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:context=".ResetPasswordFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar_resetPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView_resetPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Some Content -->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
我知道,如果我将 layout_marginTop="?attr/actionBarSize"
添加到我的 NestedScrollView 中,问题就会得到解决,但我已经看到很多示例,他们创建了我想要的视图而不添加它。
这是我为 activity
使用的样式<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:statusBarColor">#fff</item>
<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/barlow</item>
</style>
提前致谢!
appbar_scrolling_view_behavior
与 CordinatorLayout
一起使用。因此,如果 ConstraintLayout
..
CordinatorLayout
作为父项