LoadLayout快速实现加载中界面,加载错误界面,空界面等功能

来源:互联网 发布:js ajax获取网页 编辑:程序博客网 时间:2024/06/13 05:02

LoadLayout快速实现加载中界面,加载错误界面,空界面等功能

标签(空格分隔): 未分类


示意图

1.使用方法

1.引用

compile 'com.z:LoadLayout:1.0.0'

点击此处跳转github界面

2.布局中使用

    <com.z.loadlayoutlibrary.LoadLayout        android:id="@+id/loadlayout"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:contentView="@+id/content"        app:emptyView="@+id/empty"        app:errorView="@+id/error"        app:loadingView="@+id/loading">        <LinearLayout            android:id="@id/content"            android:layout_width="match_parent"            android:layout_height="match_parent">            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:text="这是主页面" />        </LinearLayout>        <include            android:id="@id/empty"            layout="@layout/empty_view"></include>        <include            android:id="@id/error"            layout="@layout/error_view"></include>        <include            android:id="@id/loading"            layout="@layout/loading_view"></include>    </com.z.loadlayoutlibrary.LoadLayout>

3.找到控件直接调用方法

mLoadlayoutLoadLayout = (LoadLayout) findViewById(R.id.loadlayout);mLoadlayoutLoadLayout.showContent();//显示主界面mLoadlayoutLoadLayout.showError();//显示错误界面mLoadlayoutLoadLayout.showEmpty();//显示空界面mLoadlayoutLoadLayout.showLoading();//显示加载中界面

2.原理

继承自frameLayout,里面有四个子布局,通过控制其显隐来实现此功能

3.注意

使用错误

<com.z.loadlayoutlibrary.LoadLayout        android:id="@+id/loadlayout"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:contentView="@+id/content"        app:emptyView="@+id/empty"//属性设置时一定要先用@+id,然后子布局中用@id        app:errorView="@+id/error"        app:loadingView="@+id/loading">

4.应用范围

任何布局中都可以套用,不存在冲突等问题,主要用于需要网络加载的页面,可根据网络情况显示不同的界面

5.感谢,原作者基础上进行修改完善,代码更加简化健壮

https://github.com/lzyzsd/LoadingLayout

0 0
原创粉丝点击