技术控

    今日:70| 主题:49409
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] EasyHeaderFooterAdapter

[复制链接]
寂寞好了 发表于 2016-10-1 16:48:01
94 0

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
EasyHeaderFooterAdapter

   Add a header and/or footer to your RecyclerView - the easy way.
   
EasyHeaderFooterAdapter-1 (download,existing,version,usually,without)

   You can download the latest sample app here .
  Features

  
       
  • Completely hassle-free. You don't have to change your existing implementation.   
  • Support for LinearLayoutManager , GridLayoutManager and StaggeredGridLayoutManager .   
  • LayoutParams of your View s are honoured.   
  • The SpanSizeLookup of your GridLayoutManager continues to work without adjustments.   
  • Support for stable ids.  
  Include in your Project

   Add this to your root build.gradle (usually in the root of your project):
  [code]repositories {
    maven { url "https://jitpack.io" }
}[/code]   And this to your module build.gradle (usually in the app directory):
  [code]dependencies {
    compile 'com.github.rubengees:EasyHeaderFooterAdapter:[email protected]'
}[/code]  If that doesn't work, look if there is a new version and the Readme was not updated yet.
  Usage

  There is almost zero configuration if you already have an adapter.
   You wrap your adapter in the EasyHeaderFooterAdapter and set it to the RecyclerView like this:
  [code]YourAdapter adapter = new YourAdapter();
EasyHeaderFooterAdapter easyHeaderFooterAdapter =
                new EasyHeaderFooterAdapter(adapter);

//Always set the LayoutManager BEFORE the adapter.
recyclerView.setLayoutManager(new SomeLayoutManager());
recyclerView.setAdapter(easyHeaderFooterAdapter);[/code]   You can then set a header or footer through the setHeader and setFooter methods:
  [code]headerFooterAdapter.setHeader(anyView);
headerFooterAdapter.setFooter(anotherView);[/code]   Those can be removed with the removeHeader and removeFooter methods:
  [code]headerFooterAdapter.removeHeader();
headerFooterAdapter.removeFooter();[/code]  And that's it! Easy right?
  There are a view things to look out for though.
  Positions

   If you are using the positions returned by the ViewHolder s getAdapterPosition method, you have to calculate the real position in your adapter. The method getRealPosition does exactly that:
  [code]adapter.setCallback(new MainAdapter.MainAdapterCallback() {
    @Override
    public void onItemClick(int position) {
        int positionInYourDataSet = headerFooterAdapter.getRealPosition(position);

        // Do whatever you wanted to do with it.
    }
});[/code]   You can find more info on that in the sample .
  ViewTypes and Ids

  The following ViewTypes and IDs are used internally, so don't use them yourself:
  [code]TYPE_HEADER = Integer.MIN_VALUE;
TYPE_FOOTER = Integer.MIN_VALUE + 1;
ID_HEADER = Long.MIN_VALUE;
ID_FOOTER = Long.MIN_VALUE + 1;[/code]   Changing the LayoutManager at runtime
   As the EasyHeaderFooterAdapter needs to configure your LayoutManager , you have to reset the adapter to the RecyclerView if you want to change the LayoutManager :
  [code]recycler.setLayoutManager(new YourNewLayoutManager());

// Remember, always set if after the LayoutManager
recycler.setAdapter(headerFooterAdapter);[/code]  Further reading

   The sample features almost all use cases. Have a look here .
   You can find the JavaDoc here .
  Metrics

  Contributions and contributors

   A guide for contribution can be found here .
友荐云推荐




上一篇:The Mysterious Fiber Bomb Problem: A Debugging Story
下一篇:security things in Linux v4.6
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表