怎么在Android中实现状态切换布局?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

1.Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}2.Add the dependency
dependencies {
implementation 'com.github.pengMaster:MultipleLayout:1.0.0'
}3.在布局中添加
注意: MultipleLayout 可做为没有标题栏的最外层布局,内部可包裹任何内容
4.代码中使用
//重试点击事件
mMultipleLayout.setOnRetryClickListener {
//模拟网络请求
Toast.makeText(this@MainActivity,"正在加载。。",Toast.LENGTH_SHORT).show()
}
//数据为空
mMultipleLayout.showEmpty()
//加载失败
mMultipleLayout.showError()
//正在加载
mMultipleLayout.showLoading()
//网络加载失败
mMultipleLayout.showNoNetwork()
//显示内容
mMultipleLayout.showContent()扩展功能
1.自定义状态布局
app:emptyView="@layout/layout_empty_view" app:errorView="@layout/layout_error_view" app:loadingView="@layout/layout_loading_view" app:noNetworkView="@layout/layout_network_view">
2.代码引入布局
//数据为空 showEmpty(int layoutId, ViewGroup.LayoutParams layoutParams) showEmpty(View view, ViewGroup.LayoutParams layoutParams) //加载失败 showError(int layoutId, ViewGroup.LayoutParams layoutParams) showError(View view, ViewGroup.LayoutParams layoutParams) //正在加载 showLoading(int layoutId, ViewGroup.LayoutParams layoutParams) showLoading(View view, ViewGroup.LayoutParams layoutParams) //网络加载失败 void showNoNetwork(int layoutId, ViewGroup.LayoutParams layoutParams) showNoNetwork(View view, ViewGroup.LayoutParams layoutParams)Android是什么
Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国Google公司和开放手机联盟领导及开发。
看完上述内容,你们掌握怎么在Android中实现状态切换布局的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!