怎么在Android中实现状态切换布局

发布时间:2021-05-24 18:13:28 作者:Leah
来源:亿速云 阅读:142

怎么在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.在布局中添加

 <king.bird.multipleview.MultipleLayout
  android:id="@+id/mMultipleLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!--任意内容-->
  <TextView
   android:id="@+id/mTvContent"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_centerInParent="true"
   android:text="@string/content" />

 </king.bird.multipleview.MultipleLayout>

注意: MultipleLayout 可做为没有标题栏的最外层布局,内部可包裹任何内容

4.代码中使用

  //重试点击事件
  mMultipleLayout.setOnRetryClickListener {
   //模拟网络请求
   Toast.makeText(this@MainActivity,"正在加载。。",Toast.LENGTH_SHORT).show()
  }
  //数据为空
  mMultipleLayout.showEmpty()
  //加载失败
  mMultipleLayout.showError()
  //正在加载
  mMultipleLayout.showLoading()
  //网络加载失败
  mMultipleLayout.showNoNetwork()
  //显示内容
  mMultipleLayout.showContent()

扩展功能

1.自定义状态布局

 <king.bird.multipleview.MultipleLayout
  android:id="@+id/multipleStatusView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  <!--自定义布局-->
  app:emptyView="@layout/layout_empty_view"
  app:errorView="@layout/layout_error_view"
  app:loadingView="@layout/layout_loading_view"
  app:noNetworkView="@layout/layout_network_view">

 </king.bird.multipleview.MultipleLayout>

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中实现状态切换布局的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. 怎么在Android中实现抖音上下滑动布局
  2. 怎么在Android中实现微信键盘切换效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:怎么在Android中通过自定义ViewGroup实现淘宝商品详情页

下一篇:使用ExpandableListView怎么实现一个二级列表购物车

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》