Simplest state switching layout

Posted by hypuk on Sun, 15 Dec 2019 18:20:07 +0100

Simplest state switching layout

Function introduction

  • Loading data
  • Data load failed
  • Data load is empty
  • Network load failed
  • Retry click event
  • Support custom layout

Rendering display

The simplest way to use it

1.Add it in your root build.gradle at the end of repositories:

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

2.Add the dependency

    dependencies {
            implementation 'com.github.pengMaster:MultipleLayout:1.0.0'
    }

3. Add in layout


    <king.bird.multipleview.MultipleLayout
        android:id="@+id/mMultipleLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--Arbitrary content-->
        <TextView
            android:id="@+id/mTvContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/content" />

    </king.bird.multipleview.MultipleLayout>

 Note: multilayout can be used as the outermost layout without title block, and any content can be wrapped inside

4. Use in code

        //Retry click event
        mMultipleLayout.setOnRetryClickListener {
            //Simulate network request
            Toast.makeText(this@MainActivity,"Loading..",Toast.LENGTH_SHORT).show()
        }
        //Data is empty.
        mMultipleLayout.showEmpty()
        //Failed to load
        mMultipleLayout.showError()
        //Loading
        mMultipleLayout.showLoading()
        //Network load failed
        mMultipleLayout.showNoNetwork()
        //show contents
        mMultipleLayout.showContent()

Extended function

1. Custom status layout

    <king.bird.multipleview.MultipleLayout
        android:id="@+id/multipleStatusView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        <!--custom layout-->
        app:emptyView="@layout/layout_empty_view"
        app:errorView="@layout/layout_error_view"
        app:loadingView="@layout/layout_loading_view"
        app:noNetworkView="@layout/layout_network_view">

    </king.bird.multipleview.MultipleLayout>

2. Code introduction layout

        //Data is empty.
        showEmpty(int layoutId, ViewGroup.LayoutParams layoutParams)
        showEmpty(View view, ViewGroup.LayoutParams layoutParams)
        //Failed to load
        showError(int layoutId, ViewGroup.LayoutParams layoutParams)
        showError(View view, ViewGroup.LayoutParams layoutParams)
        //Loading
        showLoading(int layoutId, ViewGroup.LayoutParams layoutParams)
        showLoading(View view, ViewGroup.LayoutParams layoutParams)
        //Network load failed
        void showNoNetwork(int layoutId, ViewGroup.LayoutParams layoutParams)
        showNoNetwork(View view, ViewGroup.LayoutParams layoutParams)

3. expansion

Add various pop ups later

Participation and contribution

  1. Fork this project
  2. New feat ﹣ XXX branch
  3. Submission code
  4. New Pull Request

github address

Topics: Android network github Gradle