国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android最簡單的狀態(tài)切換布局實現(xiàn)教程

2019-12-12 00:30:22
字體:
供稿:網(wǎng)友

前言

項目中經(jīng)常遇到這樣一種情況,新打開的界面需要加載數(shù)據(jù),存在多種狀態(tài)的結(jié)果,需要根據(jù)不同結(jié)果展示界面,這個過程歸納起來可以分為五種狀態(tài):初始狀態(tài)、請求狀態(tài)、空數(shù)據(jù)狀態(tài)、網(wǎng)絡(luò)錯誤狀態(tài)、成功請求狀態(tài)。 如果多個界面都存在這個流程,那么封裝整個過程的調(diào)用就很有必要了,既可以簡化調(diào)用過程,又可以很方便的管理整個流程。

下面話不多說了,來一起看看詳細的介紹吧

功能簡介

  • 正在加載數(shù)據(jù)
  • 數(shù)據(jù)加載失敗
  • 數(shù)據(jù)加載為空
  • 網(wǎng)絡(luò)加載失敗
  • 重試點擊事件
  • 支持自定義布局

效果圖展示

最簡單的使用方式

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">  <!--任意內(nèi)容-->  <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 可做為沒有標(biāo)題欄的最外層布局,內(nèi)部可包裹任何內(nèi)容

4.代碼中使用

  //重試點擊事件  mMultipleLayout.setOnRetryClickListener {   //模擬網(wǎng)絡(luò)請求   Toast.makeText(this@MainActivity,"正在加載。。",Toast.LENGTH_SHORT).show()  }  //數(shù)據(jù)為空  mMultipleLayout.showEmpty()  //加載失敗  mMultipleLayout.showError()  //正在加載  mMultipleLayout.showLoading()  //網(wǎng)絡(luò)加載失敗  mMultipleLayout.showNoNetwork()  //顯示內(nèi)容  mMultipleLayout.showContent()

擴展功能

1.自定義狀態(tài)布局

 <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.代碼引入布局

  //數(shù)據(jù)為空  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)  //網(wǎng)絡(luò)加載失敗  void showNoNetwork(int layoutId, ViewGroup.LayoutParams layoutParams)  showNoNetwork(View view, ViewGroup.LayoutParams layoutParams)

3.擴展

后續(xù)添加各種彈框

參與貢獻

  • Fork 本項目
  • 新建 Feat_xxx 分支
  • 提交代碼
  • 新建 Pull Request

github地址

項目地址:https://github.com/pengMaster/MultipleLayout

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對武林網(wǎng)的支持。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 天祝| 庆安县| 元氏县| 枣强县| 九江县| 聂拉木县| 元谋县| 定远县| 巩留县| 昭苏县| 南岸区| 河南省| 微博| 临朐县| 思茅市| 晋城| 潼南县| 景谷| 静乐县| 青浦区| 德化县| 钟祥市| 松滋市| 蒙阴县| 武平县| 大田县| 集安市| 时尚| 肇东市| 吉林省| 册亨县| 龙游县| 称多县| 吴川市| 枣强县| 大厂| 思茅市| 沁阳市| 萝北县| 准格尔旗| 诏安县|