顶部悬浮的滑动列表
一、本项目完成的功能
在上次作业类微信app中的一个可切换页面中实现下述功能:
1.用列表显示若干个英语音乐剧和法语音乐剧,以及它们的剧目名称
2.实现顶部悬浮功能,即向上滑动展示下面的内容时,分组名可以在顶部悬浮,直到该分组内容向上滑动退出屏幕页面,分组名跟随分组内容退出屏幕页面
二、布局文件
在第一次实验的基础上需要修改一个xml文件,增加两个xml文件
1.在上次作业中的tab02.xml文件中,删除TextView,拖入RecyclerView,此时系统会自动导入RecyclerView相关的依赖包
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_sticky"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:scrollbars="none" />
<include layout="@layout/sticky_include_recycle_item" />
</RelativeLayout>
2.新建两个item.xml文件,内容为TextView,用来显示分组名和分组内容
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tv_sticky_header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="20dp"
android:textColor="@android:color/white"
android:textSize="30sp"
tools:text="@string/app_name" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/sticky_include_recycle_item" />
<TextView
android:id="@+id/tv_novel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="17dp"