為RecyclerView添加頭部和腳部的UI控件:Bookends
介紹:
為RecyclerView添加頭部和腳部的UI控件,可添加多個header和footer
運行效果:

使用說明:
eclipse版本下載:http://pan.baidu.com/s/1rYOCe 不包括appcompat和RecyclerView的依賴。
Bookends會封裝傳遞給它的adapter。
其工作原理是在 getItemViewType()的返回值中添加額外的view item類型,將addHeader() 和 addFooter()提供的view映射為頭部和腳部。
使用這個類有如下的限制:
-
只對單列的列表有效(比如使用LinearLayoutManager的那種)。
-
基類adapter不能使用負的view類型,因為Bookends使用負view類型來跟蹤頭部和腳部。
-
不能添加超過1000個頭部或者腳部。
例子:
// Create your views, whatever they may be View myHeader = LayoutInflater.from(getContext()).inflate(R.layout.my_header, null); View anotherHeader = LayoutInflater.from(getContext()).inflate(R.layout.another_header, null); View myFooter = LayoutInflater.from(getContext()).inflate(R.layout.my_footer, null); // Add them as headers / footers Bookends<MyAdapter> adapter = new Bookends<MyAdapter>(myAdapter); adapter.addHeader(myHeader); adapter.addHeader(anotherHeader); adapter.addFooter(myFooter);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!