StateLayout android
--高自由度,使用簡潔
--是一個把空佈局 錯誤佈局 加載佈局 內容佈局整合成一個View的佈局
--僅提供的是思路,封裝什麼動畫,根據本身項目,在show方法添加啓動動畫,或移除動畫
[Github地址 ](https://github.com/fingdo/stateLayout/blob/master/README-zh.md)git
不要直接點擊 複製地址去找github
使用流程:網絡
1.build.gradle中maven
allprojects { repositories { maven { url "https://jitpack.io" } } }
2.導入依賴ide
//Statelayout 界面狀態快速切換 implementation 'com.github.sushanqiang:StatelayoutLibrary:v1.0.0'
3.XML佈局佈局
<com.sushanqiang.statelayout.StateLayout android:background="@color/colorFFFFFF" xmlns:sl="http://schemas.android.com/apk/res-auto" android:id="@+id/no_state_layout" android:layout_width="match_parent" android:layout_height="match_parent" sl:emptyImg="@drawable/ic_state_empty" sl:emptyText="空數據提示文字" sl:errorImg="@drawable/ic_state_error" sl:errorText="錯誤提示文字" sl:loadingText="加載提示文字" sl:loginImg="@drawable/ic_state_login" sl:loginText="登陸提示文字" sl:noNetworkImg="@drawable/ic_state_no_network" sl:noNetworkText="沒有網絡提示文字" sl:timeOutImg="@drawable/ic_state_time_out" sl:timeOutText="超時提示文字"> <!-- 內容佈局 one root view --> </com.sushanqiang.statelayout.StateLayout>
4.調用設置gradle
//調用不一樣的樣式 stateLayout.showEmptyView(); //設置頁面文字圖標 stateLayout.setTipText(StateLayout.EMPTY, "網居然崩潰了,別緊張,刷新試試"); stateLayout.setTipImg(StateLayout.EMPTY, R.mipmap.common_load_net_error); stateLayout.setUseAnimation(true);
//顯示沒有網絡視圖 stateLayout。showNoNetworkView(); //顯示超時視圖 stateLayout。showTimeoutView(); //顯示空的視圖 stateLayout。showEmptyView(); //顯示錯誤視圖 stateLayout。showErrorView(); //顯示登陸視圖 stateLayout。showLoginView();
//顯示加載視圖 stateLayout。showLoadingView();
1,顯示 2,顯示什麼時候設置字符串Id 3,顯示什麼時候設置字符串 4,顯示什麼時候設置自定義視圖,例如: 1)進度條 2)gif imageView 3)自定義視圖
5.設置點擊刷新 和登錄動畫
stateLayout.setRefreshListener(new StateLayout.OnViewRefreshListener() { //刷新 @Override public void refreshClick() { toast = new QMUITipDialog.Builder(NoActivity.this) .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) .setTipWord("正在加載") .create(); toast.show(); //登錄接口驗證 mPresenter.loadData(Concat.LANDINGTEXT); } //登錄 @Override public void loginClick() { } });
6.設置自定義頁面ui
默認是false
//使用動畫 stateLayout。setUseAnimation( true);
若是您未設置自定義動畫,則默認爲FadeScaleViewAnimProvider
動畫,若是您要設置自定義動畫
//設置anmtion stateLayout。setViewSwitchAnimProvider(新的 FadeScaleViewAnimProvider());
stateLayout
如今有2個動畫
//淡入淡出動畫 FadeScaleViewAnimProvider //淡入淡出動畫 FadeViewAnimProvider
若是你想設置自定義你的動畫,請執行 ViewAnimProvider
重寫showAnimation
和hideAnimation
方法。
//FadeViewAnimProvider.class public class FadeViewAnimProvider implements ViewAnimProvider { @Override public Animation showAnimation() { Animation animation = new AlphaAnimation(0.0f,1.0f); animation.setDuration(200); animation.setInterpolator(new DecelerateInterpolator()); return animation; } @Override public Animation hideAnimation() { Animation animation = new AlphaAnimation(1.0f,0.0f); animation.setDuration(200); animation.setInterpolator(new AccelerateDecelerateInterpolator()); return animation; } }
設置樣式參數
Styleable parameter
< declare-styleable name = 「 StateLayout 」 > <! - error tip image - > < attr name = 「 errorImg 」 format = 「 reference 」 /> <! - error tip text - > < attr name = 「 errorText 「 format = 」 string 「 /> <! -空的提示圖像- > <attr name = 「emptyImg 「 format = 」 reference 「 /> <! - empty tip text - > < attr name = 」 emptyText 「 format = 」 string 「 /> <! - no network tip image - > < attr name = 」 noNetworkImg 「 format = 」 reference 「 /> <! -沒有網絡提示文本- > <attr name = 「noNetworkText 「 format = 」 string 「 /> <! - timeout tip image - > < attr name = 」 timeOutImg 「 format = 」 reference 「 /> <! - timeout tips text - > < attr name = 」 timeOutText 「 format = 「 string 」 /> <! -登陸提示圖像- > <attr name = 「loginImg 「 format = 」 reference 「 /> <! -登陸提示文本- > < attr name = 」 loginText 「 format = 」 string 「 /> <! - loading tip text - > < attr name = 」 loadingText 「 format = 」 string 「 /> </ declare-styleable >