导入依赖:
compile 'com.bartoszlipinski.recyclerviewheader:library:1.2.0'
为头布局写一个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="wrap_content"> <com.youth.banner.Banner xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="200dp"/> </LinearLayout>
使用静态方法从xml中创建RecyclerViewHader:
RecyclerViewHeader header = RecyclerViewHeader.fromXml(getActivity(), R.layout .layout_lunbo);将recyclerViewHader attach加到recyclerView,完成!
header.attachTo(main_rec);注意事项:
RecyclerViewHeader必须在RecyclerView设置了LayoutManager之后调用。
目前该库适用于LinearLayoutManager,GridLayoutManager和StaggeredGridLayoutManager布局的RecyclerViews
本文章使用:http://www.open-open.com/lib/view/open1434422599926.html 的方法!!!