android - AppBarLayout 不会折叠
问题描述
切换到 androidx 后,以下代码停止工作。Toolbar 下方的 TextView 以前是随内容滚动的,现在不行了。有解决这个错误的办法吗?
<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:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appabr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Title" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
app:layout_constraintTop_toBottomOf="@+id/appabr">
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:lineSpacingMultiplier="2"
android:text="@string/aritical" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
代替
androidx.constraintlayout.widget.ConstraintLayout
采用
android.support.design.widget.CoordinatorLayout
作为你的根布局
推荐阅读
- python - 如何处理强化学习中不同的状态空间大小?
- javascript - 输入一个字符后,对反应输入框的关注松散
- discord.js - Discord.JS TypeError:ping 不是函数
- angular - 为什么我需要清理缓存才能在我的 Angular 应用程序中看到最新的模块?
- javascript - 当输入是javascript中的数组时搜索过滤列值
- html - Blockquote 在移动设备上没有响应
- docker - Dockerfile中的条件复制?
- azure-devops - 创建 Azure 构建管道时构建失败 - 错误 MSB3073 - VSBuild 任务
- python - 如何用 Map 和 Filter 替换 Pythonic For 循环?
- asp.net-core - 测试枚举和字符串 - .NET Core 3.1 和 xUnit