Android showing LoadingView or EmptyView for Activity or Fragment
这几天利用一些时间,整理了一下,写了一个简单的工具类,用来快速的显示LoadingView或者EmptyView,以前都是定义一个layout,根布局为FrameLayout,再在layout布局文件里面添加LoadingView或者EmptyView,然后在Activity里面设置visible属性,代码太冗余,所以在这种情况下催生了我这个小项目;
代码拖管地址:
https://github.com/a284628487/EasyLoading
现在使用这个工具类,一切都变得很简单,不需要再在Activity中或者Fragment中去定义一个成员变量,然后初始化、显示、隐藏;
现在只需要一句代码就搞定
显示LoadingView
ActivityTool.showLoading(Activity activity, int layoutId)
ActivityTool.showLoading(Activity activity, View view)
ActivityTool.showLoading(Activity activity, int layoutId, boolean dimBackground)
ActivityTool.showLoading(Activity activity, View view, boolean dimBackground)
显示EmptyView
ActivityTool.showEmpty(Activity activity, int layoutId)
ActivityTool.showEmpty(Activity activity, View view)
隐藏LoadingView或EmptyView
ActivityTool.dismiss(Activity activity)
显示的时候,只需要传入你要显示的view或者一个layoutid,LoadingView / EmptyView就显示出来了,看到这里,可能有人会想,那我还不是得传入一个View或者定义一个layout布局,确实如此。但是,在这种情况下,我们的LoadingView / EmptyView和Activity和Fragment是分开管理了的,没有任何关联,在你的Activity中和Fragment中,是看不到LoadingView / EmptyView的,也不需要在layout中定义多个ViewStub,使Fragment和Activity更加纯净,没有干扰信息;
注意:在Fragment中使用时,要求Fragment的所持有的view为FrameLayout,有两种方法,参见上面github代码托管地址;
To showing LoadingView or EmptyView in a Fragment, the Fragment’s rootView must be a FrameLayout or FrameLayout’s subclass, you can define a xml-layout which rootView is FrameLayout for the Fragment or just make your Fragment extends LoadingSupportFragment / LoadingFragment and achieve the method contentViewLayoutId() to return your xml-layoutId, and you don’t need to override the method onCreateView(); yeah, you can show the EmptyView or LoadingView simply;
为了让Fragment能够显示LoadingView或EmptyView,Fragment所创建的view必须是FrameLayout或者FrameLayout的子类,这里有两种快捷的方法,一是同往常一样,定义一个layout布局文件然后让Fragment创建view,但该layout的rootView必须为FrameLayout;二是继承LoadingFragment或者LoadingSupportFragment,并且实现方法contentViewLayoutId(),在该方法中返回自定义的layout布局文件,该布局文件则没有rootView的限制,rootView可以是任意的控件,并且,使用这种方法也就不需要再重写Fragment的onCreateView方法;
Android showing LoadingView or EmptyView for Activity or Fragment的更多相关文章
- Android:手把手教你 实现Activity 与 Fragment 相互通信,发送字符串信息(含Demo)
		前言Activity 与 Fragment 的使用在Android开发中非常多今天,我将主要讲解 Activity 与 Fragment 如何进行通信,实际上是要解决两个问题: Activity 如何 ... 
- Android 数据传递(二)Activity与fragment之间的通信
		在网上找到了一篇总结的非常好的文章,我这里就贴出他的博文地址.自己就不再写这个方面的总结了. Activity与Fragment通信(99%)完美解决方案 
- Android开发系列(一)Activity与Fragment获取屏幕获取屏幕像素的不同方式
		Activity中常用的获取屏幕像素代码: //获取屏幕像素相关信息 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getD ... 
- [Android] Android Butterknife 8.8.1 在 Activity 和 Fragment 、 Adapter 中的使用
		ButterKnife是一个专注于Android系统的View注入框架,以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤.是大神JakeW ... 
- Android窗口管理服务WindowManagerService切换Activity窗口(App Transition)的过程分析
		文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8596449 在Android系统中,同一时刻只 ... 
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
		Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ... 
- android 关闭多个或指定activity
		打开了.activityA,B,C,D,...然后到E一起关闭前面所有activity(转自:http://blog.csdn.net/lengguoxing/article/details/4214 ... 
- 查看Android应用的package name和activity name方面
		使用android自动化测试工具monkeyrunner启动应用时,需要填写被测程序的包名和启动的Activity,以下有两种查看应用包名package和入口activity名称的方法:方法一:使用a ... 
- Android Studio 小提示,新建Activity
		Android Studio是在google I/O大会上新发布的一个IDE,基于IntelliJ,Android开发除了Eclipse之外又多了一种选择. 在Android Studio中如何在当前 ... 
随机推荐
- docker解决数据存储问题的方案
			现在docker在云计算领域发展的势头很猛,各个公司不论大小都开始研究这个开源工具和技术,围绕docker的开源项目和创业公司也多如牛毛,就是一个简单管理container的web ui都有很多开源项 ... 
- Backbone事件管理——Backbone.Events模块API结构
			模块Backbone.Events的事件管理是通过Backbone提供的Events API来实现的,该API在1.0版本之前仅仅提供了几个基本的方法,如on.off.trigger.once分别执行 ... 
- spring三种实例化bean的方式
			1构造函数实例化 2静态工厂方法实例化 3实例工厂方法实例化 service接口: package service; public interface PersonService { public v ... 
- React访问组件元素的子元素(ES5与ES6的对比)
			// 创建组件var NewDom = React.createClass({ // 类名一定要大写开头 render: function () { return ( <ol> { Rea ... 
- 【VerySky原创】RPR_ABAP_SOURCE_SCAN
			[VerySky原创]RPR_ABAP_SOURCE_SCAN 扫描 ABAP 报表源 
- ListView实现Item局部刷新
			对于ListView数据的刷新大家都知道,改变Adapter的数据源,然后调用Adapter的notifyDateSetChanged()方法即可. 但是博主在做公司项目的时候,有个下载模块,因为可 ... 
- showmessage函数里
			首先说一下,漏洞是t00ls核心群传出去的,xhming先去读的,然后我后来读的,读出来的都是代码执行,1月5日夜里11点多钟,在核心群的黑客们的要求下,xhming给了个poc,我给了个exp,确实 ... 
- fidder 抓 https包配置方法(ios & android & pc浏览器)
			1. fidder抓https包的基本配置,可参见以下博文 http://blog.csdn.net/idlear/article/details/50999490 2. 遇到问题:抓包看只有Tunn ... 
- Android Audio控制和MediaButton远程控制(音视频控制配合)
			使用过Android系统的朋友应该都知道,Android里面声音是区分好几种情况,每种情况下的音频大小是独立的.也就是说你调节了电话铃声大小不会影响多媒体播放的声音大小.这个涉及了AudioStrea ... 
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
			C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ... 
