最近在做分组列表,头部悬停的效果,在github上就搜到了StickyListHeaders(https://github.com/emilsjolander/StickyListHeaders)这个库,自己动手实现了一个demo,实际效果图见文末。
引用类库:
implementation 'se.emilsjolander:stickylistheaders:2.7.0'
子布局item_pay_bill_month_body_list.xml:
<?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="match_parent" android:orientation="vertical"> <TextView android:id="@+id/item_body_tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="内容" android:textSize="20sp" /> <TextView android:id="@+id/item_body_tv2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="内容" android:textSize="20sp" /> <TextView android:id="@+id/item_body_tv3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="内容" android:textSize="20sp" /> <TextView android:id="@+id/item_body_tv4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="内容" android:textSize="20sp" /> <TextView android:id="@+id/item_body_tv5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin