Android LoadingLayout
LoadingLayout
方便的切換到加載中,空頁面,出錯頁面和內容頁面
LoadingLayout集成自Framelayout,默認把第一個子view當做內容視圖,其他的子view會被忽略
使用如下:
<com.xiaomagouche.loadinglayout.library.LoadingLayout android:id="@+id/loading_layout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is Content View" /> </RelativeLayout> </com.xiaomagouche.loadinglayout.library.LoadingLayout>
可以通過代碼來切換到不同的view
final LoadingLayout loadingLayout = (LoadingLayout) findViewById(R.id.loading_layout); findViewById(R.id.btn_show_content).setOnClickListener((view) -> loadingLayout.showContent()); findViewById(R.id.btn_show_error).setOnClickListener((view) -> loadingLayout.showError()); findViewById(R.id.btn_show_empty).setOnClickListener((view) -> loadingLayout.showEmpty()); findViewById(R.id.btn_show_loading).setOnClickListener((view) -> loadingLayout.showLoading());
另外,針對errorView和emptyView,提供了兩個重新加載的按鈕。需要注意的是,這里的重新加載的按鈕的id必須是btn_error_retry或者btn_empty_retry
loadingLayout.setOnRetryClickListener((view) -> loadingLayout.showLoading());
當然,你也可以自己自定義各種視圖
<com.xiaomagouche.loadinglayout.library.LoadingLayout android:id="@+id/loading_layout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" app:emptyView="@layout/custom_empty_view" app:loadingView="@layout/custom_loading_view"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is Content View" /> </RelativeLayout> </com.xiaomagouche.loadinglayout.library.LoadingLayout>
Gradle中使用
推薦使用jitpack
repositories { // ... maven { url "https://jitpack.io" } } dependencies { compile 'com.github.lzyzsd:XMFE-TEAM:LoadingLayout:0.1.0' }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!