欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年10月11日 09:51:05   作者:雨落文染丶  
這篇文章主要給大家介紹了關(guān)于Android中最簡單的狀態(tài)切換布局的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

項目中經(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 可做為沒有標題欄的最外層布局,內(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í)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論