android - 如何创建类似 Netflix 的折叠透明工具栏
问题描述
如何像 netflix 一样创建折叠工具栏。recyclerview 可以在状态栏后面绘制,而工具栏则不能。
我尝试创建一个,但不知何故无法让它工作。将 设置android:fitsSystemWindows="false"
为协调器布局也会影响工具栏。
示例图片
fragment_main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="false"
android:background="@color/netflix_black">
<include
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/content"
layout="@layout/layout_content"/>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/toolBarLayoutView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:background="@android:color/transparent"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src ="@drawable/logo_netflix"
/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
布局内容.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/toolBarLayoutView"
android:layout_width="match_parent"
android:background="@android:color/transparent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/parentRv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方案
推荐阅读
- mysql - 为什么mysql不执行查询?
- python - 在 jupyter notebook 中添加命令行参数
- android - 使用 textswitcher 切换文本时删除边距
- spring-boot - 端点调用使用@Transational 注释的多个方法不起作用
- java - 几个小时不活动后打开应用程序时黑屏
- c++ - 可以调整这两种方法,让我只解析一次命令行吗?
- rvest - RVest 试图抓取日期时间字段
- javascript - 尽管发送了数据,但对 Express 应用程序的请求带有空正文,但仅在一条路线中
- c# - Outlook 渲染问题
- javascript - 如何使 JS for 循环异步