stateLayout

a quick switch layout

  • 所有者: fingdo/stateLayout
  • 平台:
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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-styleable name="StateLayout">
    <!-- error tip image -->
    <attr name="errorImg" format="reference" />
    <!-- error tip text -->
    <attr name="errorText" format="string" />
    <!-- empty tip image -->
    <attr name="emptyImg" format="reference" />
    <!-- empty tip text -->
    <attr name="emptyText" format="string" />
    <!-- no network tip image -->
    <attr name="noNetworkImg" format="reference" />
    <!-- no network tip text -->
    <attr name="noNetworkText" format="string" />
    <!-- timeout tip image -->
    <attr name="timeOutImg" format="reference" />
    <!-- timeout tip text -->
    <attr name="timeOutText" format="string" />
    <!-- sign in tip image -->
    <attr name="loginImg" format="reference" />
    <!-- sign in tip text -->
    <attr name="loginText" format="string" />
    <!-- loading tip text -->
    <attr name="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 Type
public static final int ERROR = 1;
public static final int EMPTY = 2;
public static final int TIMEOUT = 3;
public static final int NOT_NETWORK = 4;
public static final int LOADING = 5;
public static final int LOGIN = 6;

image

Code show layout view

//show no network view
stateLayout.showNoNetworkView();
//show timeout view
stateLayout.showTimeoutView();
//show empty view
stateLayout.showEmptyView();
//show error view
stateLayout.showErrorView();
//show sign in view
stateLayout.showLoginView();

// such as the below pic
1,show
2,show when set string Id and image Id
3,show when set string Id
4,show when set string
5,show when set string and image Id

image

//show loading view
stateLayout.showLoadingView();

1,show
2,show when set string Id
3,show when set string
4,show when set custom view, example:
    1)progress bar
    2)gif imageView
    3)custom view

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 animation
stateLayout.setUseAnimation(true);

if you don't set custom animation,default is FadeScaleViewAnimProvider animation
if you want to set your custom animation

//set anmtion
stateLayout.setViewSwitchAnimProvider(new FadeScaleViewAnimProvider());

stateLayout have 2 animation now

// fade and scale animation
FadeScaleViewAnimProvider
// fade animation
FadeViewAnimProvider

if you want set custom your animation,please implements ViewAnimProvider

rewrite showAnimation and hideAnimation method。

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

}

Listen refresh and login click callback

please implements StateLayout.OnViewRefreshListener

rewrite method:

//refresh layout
void refreshClick();
    
//login click
void loginClick();

Thanks lufficc open source animation

主要指标

概览
名称与所有者fingdo/stateLayout
主编程语言Java
编程语言Java (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2017-03-20 06:52:00
推送于2017-10-11 03:14:37
最后一次提交2017-10-11 11:14:31
发布数5
最新版本名称1.0.4 (发布于 )
第一版名称1.0.0 (发布于 )
用户参与
星数479
关注者数9
派生数68
提交数20
已启用问题?
问题数6
打开的问题数1
拉请求数0
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?