android-appbarlayout - Androidx滚动视图行为不起作用
问题描述
切换到androidx后,以下代码停止工作。Toolbar 下方的 TextView 用于滚动内容,但现在不滚动了。只有当我将相同的 scrollFlags 设置为 Toolbar 时,我才设法让它工作,但我想保持它在适当的位置。除了将 Toolbar 移出 AppBarLayout 和 CoordinatorLayout 之外,还有其他解决方案吗?
<androidx.coordinatorlayout.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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
app:title="Non-scrollable title"
android:layout_width="wrap_content"
android:layout_height="?android:attr/actionBarSize"/>
<TextView
app:layout_scrollFlags="scroll"
android:layout_margin="16dp"
android:textSize="20sp"
android:text="this should scroll with the content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- some scrollable content here -->
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方案
替换旧属性:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
新的:
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
并添加
implementation 'com.google.android.material:material:1.0.0'
推荐阅读
- python - 使用 pandas 程序运行 Pyinstaller 时出错有限的工作区权限
- swift - Firebase 注销不改变视图工作
- java - Maven 多模块项目尝试从存储库下载内部依赖项
- c++ - 使用 c/c++ 在 mac os x 上获取最前面的应用程序的名称
- python - 从谷歌表单获取字段 ID,python BeautifulSoup
- email - 为什么电子邮件回复在回复时会复制整个线程
- python - 我创建了一个代码来完美地完成人类基准测验。为什么会失败?
- ios - 带有链接的 iOS ad-hoc 分布式应用程序不起作用
- asp.net-mvc - MVC 如何从一个控制器加载视图和局部视图
- python - python-多索引分组百分比