美文网首页Android干货Android开发Android知识
开源中国系列二:一分钟给RecyclerView添加head

开源中国系列二:一分钟给RecyclerView添加head

作者: 小怪兽打葫芦娃 | 来源:发表于2017-02-23 18:41 被阅读392次

自定义控件

联网

工具

数据库

源码分析相关面试题

Activity相关面试题

Service相关面试题

与XMPP相关面试题

与性能优化相关面试题

与登录相关面试题

与开发相关面试题

与人事相关面试题

开源项目:https://github.com/open-android/BaseRecyclerAndAdapter

使用步骤

1. 在project的build.gradle添加如下代码(如下图)

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

2. 在Module的build.gradle添加依赖

 compile 'com.github.open-android:BaseRecyclerAndAdapter:0.4.8'
 compile 'com.jakewharton:butterknife:8.4.0'
 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

3. 把如下代码复制到XML

 <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<org.itheima.recycler.widget.ItheimaRecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<org.itheima.recycler.header.RecyclerViewHeader
    android:id="@+id/recycler_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|top">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:text="header"/>
</org.itheima.recycler.header.RecyclerViewHeader></FrameLayout>

4. 把如下代码复制到java代码中

 RecyclerViewHeader mRecyclerViewHeader = (RecyclerViewHeader) findViewById(R.id.recycler_header);
 ItheimaRecyclerView mItheimaRecyclerView = (ItheimaRecyclerView)      findViewById(R.id.recycler_view);
  mRecyclerViewHeader.attachTo(mItheimaRecyclerView);
  • 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~

  • 欢迎关注微信公众号

微信公众号名称:Android干货程序员

相关文章

网友评论

  • ZHTF:官方的开源中国代码,我拉下来了,但是他的接口不让我用,无法登陆,很多api不可以请求,请问有什么办法吗
    ZHTF: @马伟奇 谢谢,马哥早
    小怪兽打葫芦娃:@China林鹏 不会呀,你看我的视频,都是通过抓包拿他们的数据

本文标题:开源中国系列二:一分钟给RecyclerView添加head

本文链接:https://www.haomeiwen.com/subject/quwbwttx.html