RecyclerView基本用法(添加分割线,添加头尾布局,下拉刷新上拉加载,添加删除item,以及监听事件)

本文介绍了如何在Android中使用RecyclerView,包括设置分割线、添加头尾布局、实现下拉刷新和上拉加载功能,以及添加删除item和监听事件的详细步骤。示例代码涵盖了布局文件、MainActivity、Adapter的实现以及监听器的设置。
摘要由CSDN通过智能技术生成
一.布局文件
           布局文件很容易看懂不多说
           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=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值