1.Add it in your root build.gradle at the end of repositories:java
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
2.Add the dependencyandroid
dependencies { implementation 'com.github.pengMaster:MultipleLayout:1.0.0' }
3.在佈局中添加git
<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.代碼中使用github
//重試點擊事件 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.代碼引入佈局app
//數據爲空 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.擴展maven
後續添加各類彈框