安卓自定义VIEW安卓开发博客Android开发

StatusView空页面|错误页面|加载中页面处理

2016-10-21  本文已影响1127人  柨柨

StatusView

Android 空页面|错误页面|加载中页面处理,支持所有的布局,使用简单方便

网络错误情况
加载中情况
数据为空情况
正常显示内容
去设置网络

使用步骤

1.根据实际需求实现StatusView

继承StatusView基类,实现各个页面的初始化,这样做的好处是我么你可以根据不同的需求,创建不同的加载页面或者其他页面的样式。也可以根据实际开发需求对各个页面进行不同的出来,比如,加载页面加载样式的不同,数据为空的页面,根据不同的调用模块 ,显示不同的内容。 可以只需要创建一次,全局使用。

Paste_Image.png

2.创建StatusLayout对象

方法一:强烈推荐,直接在代码中使用就可以。

StatusLayout statusLayout;
statusLayout =new StatusLayout.Builder()
                    .setContentView(contentView)//设置正常显示内容的VIEW
                    .setStatusView(statusView)
                     .build();

方式二:首先在XML布局中使用,然后再activity里像正常的空间

<com.bubu.status.StatusLayout    
android:id="@+id/status_layout"    
android:layout_width="match_parent"    
android:layout_height="match_parent">    
<LinearLayout        
android:layout_width="match_parent"       
android:layout_height="match_parent"        
android:background="#ef5464">        
<TextView            
android:layout_width="match_parent"            
android:layout_height="match_parent"            
android:text="正常文本内容" />   
</LinearLayout>
</com.bubu.status.StatusLayout>
StatusLayout statusLayout;
statusLayout = (StatusLayout) findViewById(R.id.status_layout);
statusLayout.setStatusView(statusView);//设置statisView

3.使用StatusLayout

statusLayout.showLoading();
statusLayout.showEmpty();
statusLayout.showContent();
statusLayout.showRetry();
statusLayout.showSetting();

用起来很方便吧,一些比较常用的VIEW ,DEMO里写了一个MyStatusView.

大家可以从这里下载https://github.com/bubula/StatusView/tree/master#statusview

暂时大家只能把library下面的文件拷贝出来使用,等弄好jcenter,就可以直接引用使用了


status
上一篇下一篇

猜你喜欢

热点阅读