效果图:
需求分析:
如上图所示,这是一个展示年级及学期的界面。 年级分为三组高中、初中和小学。 因学期太多若按一个一个控件的写既繁琐又不够优雅, 所以我采用 RecyclerView配合分组来实现效果。 注意:我这边是使用一个 RecyclerView和一个 List, 然后Adapter使用getItemViewType将填充视图分为标题和内容两个 ItemView,通过Bean中的 type 来决定加载哪个视图。 因为是三列的列表,所以在插入 item 时,标题 item 会和内容 item 在同一行,顾在插入标题 item 的时候让它跨三列即可独占一行, 具体实现如下:实现过程:
xml相关文件
<layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="gradeBean" type="cn.toctec.wrongbook.grade.bean.GradeBean" /> data> <TextView android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="@{gradeBean.gradeName}" android:textSize="12dp" android:textColor="@color/color888888"> TextView>layout>
标题 item.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="gradeBean" type="cn.toctec.wrongbook.grade.bean.GradeBean" /> data> <com.nanbox.ripplelayout.RippleLayout android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/bg_grade_gray_fillet"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_c