Android 加了一个上拉刷新,下拉加载的布局

在这里插入图片描述
记得是在gridview里面放的

链接在这里

1.在 build.gradle 中添加依赖
可能加载不成功,就去搜索依赖,搜索时不要带版本号,我是将版本号改成2.0.5就可以了的

implementation 'androidx.appcompat:appcompat:1.0.0'                 //必须 1.0.0 以上

implementation  'io.github.scwang90:refresh-layout-kernel:2.0.3'      //核心必须依赖
implementation  'io.github.scwang90:refresh-header-classics:2.0.3'    //经典刷新头
implementation  'io.github.scwang90:refresh-header-radar:2.0.3'       //雷达刷新头
implementation  'io.github.scwang90:refresh-header-falsify:2.0.3'     //虚拟刷新头
implementation  'io.github.scwang90:refresh-header-material:2.0.3'    //谷歌刷新头
implementation  'io.github.scwang90:refresh-header-two-level:2.0.3'   //二级刷新头
implementation  'io.github.scwang90:refresh-footer-ball:2.0.3'        //球脉冲加载
implementation  'io.github.scwang90:refresh-footer-classics:2.0.3'    //经典加载


如果使用 AndroidX 先在 gradle.properties 中添加,两行都不能少噢~

android.useAndroidX=true
android.enableJetifier=true

2.在XML布局文件中添加 SmartRefreshLayout

<?xml version="1.0" encoding="utf-8"?>
<com.scwang.smart.refresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/refreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.scwang.smart.refresh.header.ClassicsHeader
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="never"
        android:background="#fff" />
    <com.scwang.smart.refresh.footer.ClassicsFooter
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>

3.在 Activity 或者 Fragment 中添加代码

RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setRefreshFooter(new ClassicsFooter(this));
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh(RefreshLayout refreshlayout) {
        refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
    }
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
    @Override
    public void onLoadMore(RefreshLayout refreshlayout) {
        refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
    }
});

如果是在fragment,就将this改成requireContext()

V p n用弄子里,不然有点难加载github

下面是首页的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#020202">

    <com.example.app5.view.ActionBarView
        android:id="@+id/action_bar"
        android:layout_width="match_parent"
        android:title="@string/recommend"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/iv_firstpage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:background="@color/transparent"
        android:adjustViewBounds="true"
        android:src="@mipmap/firstpage" />

    <GridView
        android:id="@+id/gview"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:horizontalSpacing="10dp"
        android:scrollbars="none"
        android:verticalSpacing="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="2" />

</LinearLayout>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值