android - 为什么我的内容显示在我的 Appbar 下方?
问题描述
我正在尝试添加一个 AppBarLayout,当不需要滚动(或内容尚未滚动)时,elavation 为 0,但是当用户可以滚动或滚动时,则会显示 elavation(如 Google Tasks应用程序)。在新材料 Appbar 文档中,我发现将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 问题将得到解决,但我已经看到了很多示例,他们创建了我想要的视图而不添加它。
这是我在活动中使用的风格
<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
. 所以你需要使用CordinatorLayout
作为父母而不是如果ConstraintLayout
..
推荐阅读
- python - Nuke Python 在 nuke 脚本文件中保存工具设置
- html - 如何使用 CSS 自定义复选框?
- reactjs - ApolloProvider 客户端 - 如何从 React Class 组件访问?
- python - 如何强制python使用cmd而不是powershell执行命令
- swift - Swift 程序中的 Firebase 存储参考问题
- javascript - 难以将前端应用程序部署到谷歌应用程序引擎
- web-services - 为什么 webservice 在 Xamarin Forms 中抛出空指针
- angular - Angular - 使用现有的 ngForm 可选
- r - 将列转换为 gt 表对象中的摘要行
- vue.js - 无法使用 vuetify 的图标