Skip to content

Repository files navigation

StateLayout usage

Demo

sample

Dependently

  • 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'

中文文档点这里

add in your xml

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>

Styleable parameter

<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>

sample:

<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>

Code set icon and text (show before)

if you set null,will use last time tip text.set "" can show,only show tip image.

//StateLayout Constants TypepublicstaticfinalintERROR = 1;
publicstaticfinalintEMPTY = 2;
publicstaticfinalintTIMEOUT = 3;
publicstaticfinalintNOT_NETWORK = 4;
publicstaticfinalintLOADING = 5;
publicstaticfinalintLOGIN = 6;

image

Code show layout view

//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 pic1show2showwhensetstringIdandimageId3showwhensetstringId4show when setstring5show when setstringandimageId

image

//show loading viewstateLayout.showLoadingView();
1show2showwhensetstringId3showwhensetstring4showwhensetcustomview, example:
1)progressbar2)gifimageView3)customview

image

// show your custom view(not state view)stateLayout.showCustomView();

show when set your custom view: image

Set switch animation

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 animationFadeViewAnimProvider

if 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;
}
}

Listen refresh and login click callback

please implements StateLayout.OnViewRefreshListener

rewrite method:

//refresh layoutvoidrefreshClick();
//login clickvoidloginClick();

Thanks lufficc open source animation

About

a quick switch layout

Resources

Stars

473 stars

Watchers

9 watching

Forks

Releases

Packages

Contributors

Languages