LoadingLayout profile

LoadingLayout is a library of different states for loading data in Android (essentially a custom control). Project address: github.com/xiong-it/Lo… Welcome to experience.

Compile

Open build.gradle in your App Module and add dependencies:

compile 'tech. Michaelx. Loadinglibrary: loadinglibrary: 1.0.2'Copy the code

Sample

Use the following in the layout XML:

<?xml version="1.0" encoding="utf-8"? >
<tech.michaelx.loadinglibrary.LoadingLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/loading_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="LoadingBackground can be a drawable or a color"
    android:padding="10dp"
    app:emptyView="@layout/empty_layout"
    app:errorView="@layout/failure_layout"
    app:loadingAnimator="@animator/loading"
    app:loadingBackground="#1296db"
    app:loadingView="@layout/loading_layout"
    app:retryLoadAlways="true"
    app:showLoadingDebug="true">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This page uses properties to customize loading various states" />

</tech.michaelx.loadinglibrary.LoadingLayout>Copy the code

Custom attributes are commonly used

App :loadingView=”@layout/loading_layout” : specifies the display layout when loading, can be empty, Void ProgressBar app:loadingAnimator=”@animator/loading”: This property is valid only when specified. LoadingBackground =”#1296db” loadingBackground=”#1296db” loadingBackground=”#1296db” loadingBackground=”#1296db” Default adnroID :color/white app:emptyView=”@layout/empty_layout”: specifies the display layout when the data is empty. App :errorView=”@layout/failure_layout”: specifies the display layout when loading fails. It can be empty with default layout. App :retryLoadAlways=”true”: indicates whether to enable debugging of layout preview. The default value is false. After this function is enabled, you can preview the layout file in AS normally. Please write false when packing. See other properties for more

<resources>
    <declare-styleable name="LoadingLayout">
        <! -- Set the data to empty layout-->  
        <attr name="emptyView" format="reference" />
        <! Layout failed to load -->  
        <attr name="errorView" format="reference" />
        <! Set layout in load -->  
        <attr name="loadingView" format="reference" />
        <! -- Set loading animation ID -->  
        <attr name="loadingAnimator" format="reference" />
        <! Set the loading background, or color -->  
        <attr name="loadingBackground" format="reference|color" />
        <! Progressbar drawable-->  
        <attr name="loadingProgressDrawable" format="reference" />
        <! -- Set data to null -->  
        <attr name="emptyDrawable" format="reference" />
        <! -- Set data to null prompt -->  
        <attr name="emptyText" format="string" />
        <! -- Set the image when loading failed -->  
        <attr name="errorDrawable" format="reference" />
        <! -- Set the prompt for loading failure -->  
        <attr name="errorText" format="string" />
        <! -- Set whether to always hit retry, whether data is empty or failed, default false-->  
        <attr name="retryLoadAlways" format="boolean" />
        <! -- Set automatic display load debugging -->  
        <attr name="showLoadingDebug" format="boolean" />
    </declare-styleable>
</resources>Copy the code

The Activity/fragments of code

// Initialize the layout object
mLoadingLayout = (LoadingLayout) findViewById(R.id.loading_layout);  

// The loading is complete/the loading is successful
mLoadingLayout.loadComplete();  

// Data is null
mLoadingLayout.showEmpty();  

// Load failed
mLoadingLayout.loadFailure();  

// Set click retry listening
mLoadingLayout.setOnRetryLoadListener(OnRetryLoadListener);  

// Display is loading
// This code calls setLoadingView() to manually call showLoading().
mLoadingLayout.showLoading();Copy the code

rendering

Loading, loading complete, data is empty, loading failed, click retry several state demo GIF

Load several state demonstrations

Matters needing attention

Annotations LoadingLayout relies on Annotations from AppCompat-v7 and Support-Annotations. Please add these two dependencies to the project (version can be customized, no lower than 25.3.1 is recommended) :

The compile "com. Android. Support: appcompat - v7:25.3.1"

The compile 'com. Android. Support: support - annotations: 25.3.1'Copy the code

The project address

Thanks for reading, welcome to experience: github.com/xiong-it/Lo…