Android 加了一个上拉刷新,下拉加载的布局
Android 一个 加载 布局 刷新 上拉
2023-09-14 09:04:29 时间
记得是在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>
相关文章
- Android问题-打开DelphiXE8与DelphiXE10新建一个空工程提示"out of memory"
- 一个android应用开发的感悟
- Android 一个apk多个ICON执行入口
- EasyCamera Android安卓移动视频监控单兵设备接入EasyDarwin开源流媒体云平台
- Android学习---通过内容提供者(ContentProvider)操作另外一个应用私有数据库的内容
- Android px、dp、sp之间相互转换
- eclipse启动两个android模拟器
- android studio快捷键
- Android--数据库数据显示至屏幕
- Android中文API(97)—— ContextMenu
- Android版OpenCV图像处理技术亲自验证[二十]之朦胧之美(附源码)
- SAP UI5 应用开发教程之五十 - 如何使用 Cordova 将 SAP UI5 应用生成一个能在 Android 手机上安装的混合应用试读版
- android安卓应用和OBD的集成场景
- SAP UI5 应用开发教程之五十 - 如何使用 Cordova 将 SAP UI5 应用生成一个能在 Android 手机上安装的混合应用试读版
- Android问题笔记 - Android10适配有权限但是无法读写sdcard中文件问题
- Android 高仿QQ空间广告位 ——— 一个位置来回切换两张广告图
- Android学习路线(二十一)运用Fragment构建动态UI——创建一个Fragment
- android假设重写onDraw实现一个相似TextView能够显示表情和链接的控件(一)
- Android Afinal框架学习(二) FinalActivity 一个IOC框架
- Android 屏幕手势滑动中onFling()函数的技巧分析
- 做一个懒COCOS2D-X程序猿(一)停止手打所有cpp文件到android.mk
- [Android开发教程]Android官网developer training中文版教程 - 1.1.1 创建一个Android项目
- Android在如何建立一个WebServer
- (Android+IOS)我们正在做一个新闻App,做几乎一样的,倾听您的建议 (画画)
- android:怎么实现一个控件与另一个指定控件左对齐
- Android N 新特性 + APP开发注意事项
- 同步、更新、下载Android Source & SDK from 国内镜像站
- Android kotlin (美团app左右滑动菜单栏)用RecyclerView(androidx+BRVAH3.0.6)实现ViewPager(androidx+左右滑动)菜单栏功能