ZK安卓开发工具箱Android知识Android开发

XStateController,几近完美的状态控制机来袭

2017-02-05  本文已影响977人  droidlover

StateController顾名思义:状态控制机,用作几个状态的切换。该控件可以在Loading & Empty & Error& Content四个状态的自定义动画切换。https://github.com/limedroid/XStateController欢迎star。

screenshot.png

使用

 <cn.droidlover.xstatecontroller.XStateController
        android:id="@+id/controller"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:x_emptyLayoutId="@layout/view_empty">
       

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#854678"
            android:gravity="center"
            android:text="Content"
            android:textColor="@android:color/white"
            android:textSize="28sp" />

    </cn.droidlover.xstatecontroller.XStateController>

说明

attrs设置状态布局资源

 <attr name="x_contentLayoutId" format="reference" />
 <attr name="x_loadingLayoutId" format="reference" />
 <attr name="x_emptyLayoutId" format="reference" />
 <attr name="x_errorLayoutId" format="reference" />

常见api

设置各状态的布局资源

loadingView(loadingView);  //设置加载中的view
emptyView(emptyView);   //设置空view
errorView(errorView);   //设置errorView
contentView(contentView); //设置contentView

状态切换

showLoading();      //切换到loading状态
showError();        //切换到error状态
showEmpty();        //切换到empty状态
showContent();      //切换到content状态

注册状态切换回调

registerStateChangeListener(xx);

回调的定义

public interface OnStateChangeListener {
        //状态切换时回调,oldState当前状态,newState目标状态
        void onStateChange(int oldState, int newState);
        //动画,可自定义切换动画
        void animationState(View exitView, View enterView);
    }

使用时可直接继承SimpleStateChangeListener

上一篇 下一篇

猜你喜欢

热点阅读