- one step
add to your project
build.gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}- second step
compile 'com.github.fingdo:stateLayout:1.0.4'Usage is consistent with ScrollView, allowing only one root layout
<com.fingdo.statelayout.StateLayout
android:id="@+id/state_layout"android:layout_width="match_parent"android:layout_height="match_parent">
<!-- 内容布局 one root view -->
</com.fingdo.statelayout.StateLayout><declare-styleablename="StateLayout">
<!-- error tip image -->
<attrname="errorImg"format="reference" />
<!-- error tip text -->
<attrname="errorText"format="string" />
<!-- empty tip image -->
<attrname="emptyImg"format="reference" />
<!-- empty tip text -->
<attrname="emptyText"format="string" />
<!-- no network tip image -->
<attrname="noNetworkImg"format="reference" />
<!-- no network tip text -->
<attrname="noNetworkText"format="string" />
<!-- timeout tip image -->
<attrname="timeOutImg"format="reference" />
<!-- timeout tip text -->
<attrname="timeOutText"format="string" />
<!-- sign in tip image -->
<attrname="loginImg"format="reference" />
<!-- sign in tip text -->
<attrname="loginText"format="string" />
<!-- loading tip text -->
<attrname="loadingText"format="string" />
</declare-styleable><com.fingdo.statelayout.StateLayout
xmlns:sl="http://schemas.android.com/apk/res-auto"android:id="@+id/state_layout"android:layout_width="match_parent"android:layout_height="match_parent"sl:emptyImg="@drawable/ic_state_empty"sl:emptyText="Empty"sl:errorImg="@drawable/ic_state_error"sl:errorText="Error"sl:loadingText="Loading..."sl:loginImg="@drawable/ic_state_login"sl:loginText="Sign in"sl:noNetworkImg="@drawable/ic_state_no_network"sl:noNetworkText="No Network"sl:timeOutImg="@drawable/ic_state_time_out"sl:timeOutText="Timeout">
</com.fingdo.statelayout.StateLayout>//StateLayout Constants TypepublicstaticfinalintERROR = 1;
publicstaticfinalintEMPTY = 2;
publicstaticfinalintTIMEOUT = 3;
publicstaticfinalintNOT_NETWORK = 4;
publicstaticfinalintLOADING = 5;
publicstaticfinalintLOGIN = 6;//show no network viewstateLayout.showNoNetworkView();
//show timeout viewstateLayout.showTimeoutView();
//show empty viewstateLayout.showEmptyView();
//show error viewstateLayout.showErrorView();
//show sign in viewstateLayout.showLoginView();
// such as the below pic1,show2,showwhensetstringIdandimageId3,showwhensetstringId4,show when setstring5,show when setstringandimageId//show loading viewstateLayout.showLoadingView();
1,show2,showwhensetstringId3,showwhensetstring4,showwhensetcustomview, example:
1)progressbar2)gifimageView3)customview// show your custom view(not state view)stateLayout.showCustomView();show when set your custom view:
animation default is false,if you want to use animation
// use animationstateLayout.setUseAnimation(true);if you don't set custom animation,default is FadeScaleViewAnimProvider animation
if you want to set your custom animation
//set anmtionstateLayout.setViewSwitchAnimProvider(newFadeScaleViewAnimProvider());stateLayout have 2 animation now
// fade and scale animationFadeScaleViewAnimProvider// fade animationFadeViewAnimProviderif you want set custom your animation,please implements ViewAnimProvider
rewrite showAnimation and hideAnimation method。
//FadeViewAnimProvider.classpublicclassFadeViewAnimProviderimplementsViewAnimProvider {
@OverridepublicAnimationshowAnimation() {
Animationanimation = newAlphaAnimation(0.0f,1.0f);
animation.setDuration(200);
animation.setInterpolator(newDecelerateInterpolator());
returnanimation;
}
@OverridepublicAnimationhideAnimation() {
Animationanimation = newAlphaAnimation(1.0f,0.0f);
animation.setDuration(200);
animation.setInterpolator(newAccelerateDecelerateInterpolator());
returnanimation;
}
}please implements StateLayout.OnViewRefreshListener。
rewrite method:
//refresh layoutvoidrefreshClick();
//login clickvoidloginClick();Thanks lufficc open source animation




