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
后续添加各类弹框