/ Layout

A simple layout to display different screen of state, like loading, error, empty etc

A simple layout to display different screen of state, like loading, error, empty etc

StateLayout

A simple layout to display different screen of state, like loading, error, empty etc.

StateLayout

Usage

Add Gradle dependency:

dependencies {
    implementation 'com.shouquan:StateLayout:1.0.0'
}

An example of usage in layout xml:

<com.shouquan.statelayout.StateLayout
    android:id="@+id/layout_state"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:sl_loading_view="@layout/view_loading"
    app:sl_error_view="@layout/view_error">
    
    <!-- your content here -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the content."
        android:layout_gravity="center" />

</com.shouquan.statelayout.StateLayout>

Switch state:

setState(StateLayout.STATE_LOADING)

There are 3 build-in state:

  • STATE_CONTENT
  • STATE_LOADING
  • STATE_ERROR

You can also add your own state like this:

setViewForState(STATE_EMPTY, R.layout.view_empty)

Get the state view:

getView(StateLayout.STATE_ERROR)

GitHub