一.布局文件
布局文件很容易看懂不多说
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.wy.materialdegign.MainActivity">
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#ffff00"
android:dividerHeight="10dp"
></android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
2.头布局(尾布局基本一致)
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="8dp"
app:cardBackgroundColor="#4ff"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Header"
android:textSize="50dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
3.item.xml
这里使用了CardView(卡片):每一个item的效果如同卡片一样。之后的代码中有对其使用的介绍。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardBackgroundColor="#44ff0000"
app:cardCornerRadius="4dp"
app:cardElevation="4dp">
<TextView
android:id="@+id/textview"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="没有数据"
/>
</android.support.v7.widget.CardView>
二,MainActivity
//初始化
mRecycler=