android 状态布局,StatusLayoutSimple-android

先放下StatusLayout效果

1.默认设置的四种状态

2.自定义布局以网络错误为例

3.自定义全局状态布局样式

如何使用

A.添加行家地址

allprojects {

repositories {

google()

jcenter()

maven {

url "https://dl.bintray.com/yemao02/support"

}

}

}

B.添加库

implementation 'yemao.support:widget:1.0.0@aar'

1.在需要状态布局的布局用StatusLayout包裹起来

android:id="@+id/statusLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:text="我是内容"

/>

StatusLayout中5个方法分别为。

showEmpty()//显示空布局

showLoading()//显示加载中布局

showLoadError()//显示加载失败布局

showNetworkError()//显示网络错误布局

showContent()//显示主布局

触发各个状态布局

高级功能

。自定义各个状态布局:需继承自BasicStatusLayout

例如:

mStatusLayout!!.setNetworkError(object : BasicStatusLayout(this@MainActivity) {

override fun getLayoutId(): Int {

return R.layout.view_layout_my_network

}

override fun getRetryId(): Int {

return R.id.btn_retry

}

})

BasicStatusLayout介绍:

继承自的的的LinearLayout里面有两个方法需实现

@LayoutRes int getLayoutId();//页面布局Id

@IdRes int getRetryId();//页面重试按钮id

。重试按钮监听

mStatusLayout.setOnRetryListener(new StatusLayout.OnRetryListener() {

@Override

public void onRetry() {

}

});

。设置全局StatusLayout(在应用中设置四种状态空布局,加载中,加载失败,网络错误,当某个地方使用StatusLayout时如果没有主动设置某个状态的布局时,默认使用全局的布局样式)

public class App extends Application {

@Override

public void onCreate() {

super.onCreate();

StatusLayout.setDefaultStatusCreator(new DefaultStatusCreator() {

@Override

public BasicStatusLayout emptyLayout() {

return new BasicStatusLayout(getApplicationContext()) {

@Override

public int getLayoutId() {

return R.layout.view_layout_default_empty;

}

@Override

public int getRetryId() {

return 0;

}

};

}

@Override

public BasicStatusLayout loadingLayout() {

return new BasicStatusLayout(getApplicationContext()) {

@Override

public int getLayoutId() {

return R.layout.view_layout_default_loading;

}

@Override

public int getRetryId() {

return 0;

}

};

}

@Override

public BasicStatusLayout loadErrorLayout() {

return new BasicStatusLayout(getApplicationContext()) {

@Override

public int getLayoutId() {

return R.layout.view_layout_default_load_error;

}

@Override

public int getRetryId() {

return R.id.btn_retry;

}

};

}

@Override

public BasicStatusLayout networkErrorLayout() {

return new BasicStatusLayout(getApplicationContext()) {

@Override

public int getLayoutId() {

return R.layout.view_layout_default_network;

}

@Override

public int getRetryId() {

return R.id.btn_retry;

}

};

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值