如上图所示,此页面包含两个RecyclerView的嵌套实现,外层为瀑布流布局,里层为线性布局。
1 里层线性布局书籍列表部分
1.1 ChildAdapter
public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ChildViewHolder> {
private List<String> mBooks;
private int mLayoutId;
public ChildAdapter(List<String> list, int layoutId) {
mBooks = list;
mLayoutId = layoutId;
}
@NonNull
@Override
public ChildViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(mLayoutId, viewGroup, false);
return new ChildViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ChildViewHolder childViewHolder, int i) {
childViewHolder.textView.setText(mBooks.get(i));
}
@Override
public int getItemCount() {
return mBooks.size();
}
static class ChildViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public ChildViewHolder(View view) {
super(view);
textView = (TextView) view.findViewById(R.id.text_book);
}
}
}
1.2 对应的layout
<?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">
<TextView
android:id="@+id/text_book"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
1.3 BookShelf数据对象
public class BookShelf {
private String name;
private List<String> books;
public void setName(String name) {
this