最簡單的狀態切換佈局
功能簡介
- 正在載入資料
- 資料載入失敗
- 資料載入為空
- 網路載入失敗
- 重試點選事件
- 支援自定義佈局
效果圖展示

效果圖
最簡單的使用方式
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)
3.擴充套件
後續新增各種彈框
參與貢獻
- Fork 本專案
- 新建 Feat_xxx 分支
- 提交程式碼
- 新建 Pull Request
github地址
- 專案地址: ofollow,noindex">https://github.com/pengMaster/MultipleLayout