今天学习到了RecyclerView,有人提出让我在RecyclerView前面添加头部,之前写ListView的时候可以添加HeaderView,但是现在显然没有了,怎么办呢?在网上查了一圈发现都有点复杂,那没办法了,慢慢来写呗,但是我并没有给头部添加点击事件。就是简单的展示一下怎么添加头部。
效果图
那么实现这样的布局就用到了RecyclerView, RecyclerView的具体创建方法就请大家移步到别的博客啦。
主XML布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.practice.chapter8.section3.FloatingSearchActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
RecyclerView中的item布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.