Android:使用LoadingLayout来展示加载数据时不同状态
来源:互联网 发布:asp程序 域名绑定授权 编辑:程序博客网 时间:2024/06/05 11:42
LoadingLayout简介
应用于Android中的一个加载数据不同状态的类库(自定义控件)。
Compile
打开你的app module中的build.gradle,添加依赖:
compile 'tech.michaelx.loadinglibrary:loadinglibrary:1.0.2'
最新版本号请参看最上方徽标
Sample
在layout的xml中使用如下:
<?xml version="1.0" encoding="utf-8"?><tech.michaelx.loadinglibrary.LoadingLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/loading_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="loadingBackground可以是drawable或者颜色" android:padding="10dp" app:emptyView="@layout/empty_layout" app:errorView="@layout/failure_layout" app:loadingAnimator="@animator/loading" app:loadingBackground="#1296db" app:loadingView="@layout/loading_layout" app:retryLoadAlways="true" app:showLoadingDebug="true"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="本页面使用属性自定义loading各种状态" /></tech.michaelx.loadinglibrary.LoadingLayout>
常用自定义属性
app:loadingView="@layout/loading_layout"
:指定加载时的展示布局,可以为空,为空时使用系统默认ProgressBar app:loadingAnimator="@animator/loading"
:只用上述属性制定时,该属性方可生效,作用于加载布局的动画 app:loadingBackground="#1296db"
:指定加载过程中页面背景,可以是颜色或者drawable,默认为adnroid:color/white app:emptyView="@layout/empty_layout"
:指定了数据为空时的展示布局,可以为空,有默认布局,详细可看下方演示gif图 app:errorView="@layout/failure_layout"
:指定加载失败时的展示布局,可以为空,有默认布局,详细可看下方演示gif图 app:retryLoadAlways="true"
:是否开启数据为空时点击重试,默认为false app:showLoadingDebug="true"
:是否开启布局预览调试,默认为false,开启后可以在AS中正常预览布局文件,打包时请一定写false!
其他更多属性请看
<resources> <declare-styleable name="LoadingLayout"> <!--设置数据为空的layout--> <attr name="emptyView" format="reference" /> <!--设置加载失败的layout--> <attr name="errorView" format="reference" /> <!--设置加载中的layout--> <attr name="loadingView" format="reference" /> <!--设置加载动画id--> <attr name="loadingAnimator" format="reference" /> <!--设置加载中的背景,或者颜色--> <attr name="loadingBackground" format="reference|color" /> <!--设置默认Progressbar的progress_drawable--> <attr name="loadingProgressDrawable" format="reference" /> <!--设置数据为空时的图片--> <attr name="emptyDrawable" format="reference" /> <!--设置数据为空时的提示语--> <attr name="emptyText" format="string" /> <!--设置加载失败时的图片--> <attr name="errorDrawable" format="reference" /> <!--设置加载失败时的提示语--> <attr name="errorText" format="string" /> <!--设置是否总是点击重试,无论数据为空或者失败,默认false--> <attr name="retryLoadAlways" format="boolean" /> <!--设置自动显示加载调试--> <attr name="showLoadingDebug" format="boolean" /> </declare-styleable></resources>
Activity/Fragment代码中
// 初始化布局对象 mLoadingLayout = (LoadingLayout) findViewById(R.id.loading_layout); // 加载完毕/加载成功 mLoadingLayout.loadComplete(); // 数据为空 mLoadingLayout.showEmpty(); // 加载失败 mLoadingLayout.loadFailure(); // 设置点击重试监听 mLoadingLayout.setOnRetryLoadListener(OnRetryLoadListener); // 显示加载中 // 代码调用了setLoadingView(),才需要手动调用showLoading()mLoadingLayout.showLoading();
效果图
加载中,加载完成,数据为空,加载失败,点击重试 几种状态演示gif
注意事项
LoadingLayout需要依赖于appcompat-v7
&support-annotations
,请在工程中添加这两个依赖(版本可自定义,不建议低于25.3.1):
compile "com.android.support:appcompat-v7:25.3.1" compile 'com.android.support:support-annotations:25.3.1'
项目地址
感谢阅读,欢迎体验:https://github.com/xiong-it/LoadingLayout
- Android:使用LoadingLayout来展示加载数据时不同状态
- 能展示不同页面的加载LoadingLayout布局
- Android使用统计图AChartEngine 来展示数据
- 自定义页面加载LoadingLayout
- Android在WebView加载数据时展示loading的Dialog
- android之LoadingLayout
- Android WebView使用loadData方法来加载html数据
- Android 使用 selector 来改变TextView在不同状态下的textColor和background
- android:Activity中切换不同状态页:加载中,加载失败,数据页,空页面……
- Android listView同时展示多种不同数据的item
- Android自定义View之LoadingLayout
- 使用 ButtonGroup 来管理不同状态的 Button 按钮组
- Code Fragment-使用枚举来代表不同的状态
- 使用Jquery插件jsonview来展示json数据
- Android使用ListView展示列表数据
- Android Tabhost使用(展示不同的Tab页)
- 106_不同状态的页面展示
- android使用SharedPreferences来跳转不同页面
- 刚毕业就能拿到56万年薪?对!看看Twitter机器学习大牛写给你的进阶手册吧
- 创建无向图并深度优先搜索
- python正则表达式匹配邮箱地址是否合法
- Linux 挂载2T以上存储
- 【Scikit-Learn 中文文档】线性和二次判别分析
- Android:使用LoadingLayout来展示加载数据时不同状态
- 《01.Spring Boot实战:Spring Boot入门篇》
- 匠牛社区AM5728 USB测试
- head first冒泡排序
- 【Scikit-Learn 中文文档】内核岭回归
- NOIP普及组总结
- 购物车,增加,删除,模糊查询隔行变色+排序
- 如何在VB中设置一个提示框,有"确定","取消"2个按钮
- 一周AI看点 | AI界的体操运动员Atlas上线,第一家金融AI公司纽交所上市