Android Custom View Loadinglayout

Source: Internet
Author: User

Introduced

The previous post wrote a generic load view, which is loadinglayout on the first layer of the package to load the view, with the main purpose of eliminating the need to hide the main content layout each time it is loaded, and then display the main content layout after the load succeeds. If you do not know Loadingview, you can simply look at the previous blog: Android custom Universal Loadingview, the implementation of the principle is very simple, is loadinglayout in the content layer of the package, based on In the code to add Loadingview as a second sub-view, so do not do too much to explain, we read the direct download source reference.

Loadinglayout

This was a view for simplify the operation to loading

An app load data is usually displayed loading status, after loading successfully display the main content view, if it is a list of data, such as Listview,gridview,recyclerview generally do not have to set the main content view hidden,
But if the main view some controls such as TextView will take effect instead of a blank, we usually need to hide the main view, backfill the data after the request to the data and show the master, and these things are always cumbersome to set up in the code,
The purpose of the control is to simplify these steps.

Characteristics

1, simple to use, the principle of implementation is simple.

2. Support custom views, just set the view you want to show in

3. Support setting error View click event.

Here is just to provide a thought, we can download the source code to modify the most suitable for your view.

Use

1, the XML declaration view, wrapped in the content view of the outer layer.

<?xml version= "1.0" encoding= "Utf-8"?><Com.qiangyuyang.demo.widget.CommonLoadingLayout    xmlns:android="Http://schemas.android.com/apk/res/android"    Android:id="@+id/loadinglayout"    Android:layout_width="Match_parent"    Android:layout_height="Match_parent"    Android:paddingbottom="@dimen/activity_vertical_margin"    Android:paddingleft="@dimen/activity_horizontal_margin"    Android:paddingright="@dimen/activity_horizontal_margin"    Android:paddingtop="@dimen/activity_vertical_margin">    <TextViewandroid:layout_width="Match_parent"android:layout_height ="Match_parent"android:text="main content"/>                        </com.qiangyuyang.demo.widget.CommonLoadingLayout>

2, Java code to get the control and at the appropriate time to call the loading, loading failure, loading successful methods.

 Public  class loadinglayoutactivity extends appcompatactivity {    protectedCommonloadinglayout mloadinglayout;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);Super. Setcontentview (R.layout.activity_loading_layout); Mloadinglayout = (commonloadinglayout) Findviewbyid (r.id.loadinglayout);//Set error View Click Reload EventMloadinglayout.setloadinghandler (NewCommonloadingview.loadinghandler () {@Override             Public void Dorequestdata() {mloadinglayout.load (); Mloadinglayout.postdelayed (NewRunnable () {@Override                     Public void Run() {mloadinglayout.loadsuccess (); }                }, the); }        });//error occurred after simulating load of network requestMloadinglayout.load (); Mloadinglayout.postdelayed (NewRunnable () {@Override             Public void Run() {mloadinglayout.loaderror (); }        }, the); }}

3, custom loading, loading errors, and other views.

        new ProgressBar(this);        this.mLoadingLayout.setLoadingView(progressBar);        new TextView(this);        textView.setText("加载失败...");        this.mLoadingLayout.setLoadingErrorView(textView);        mLoadingLayout.load();
SOURCE download

Https://github.com/yissan/LoadingLayout

If my article is helpful to you, please move hands to praise or concern, your support will be my eternal power.

Android Custom View Loadinglayout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.