Load page masking time-consuming Operations task page--third party open source--androidprogresslayout

Source: Internet
Author: User

In the development of Android, there are often such requirements, such as a time-consuming operation, networking to obtain network images, content, database time-consuming reading and writing, and so on, during this time-consuming operation, the developer may not want users to do other operations (other operations may cause logic confusion), At this point, you need to give the user an additional load page to block the main logic code to run, to the master page after the time-consuming operation is complete, automatically disappear so load over page, to restore the normal should display the page.

For example, if the code uses Android WebView to open a Web page link trying to load a website, but the network quality is not good, it takes a long time, then in this process, the better user experience is to give the user a loading Progress page, blocking the webview. When the loaded content is successful, switch back to the normal logical page completely.
Android Androidprogresslayout implements such a feature that Android Androidprogresslayout on GitHub on the project homepage is: Https://github.com/antonkrasov /androidprogresslayout

The test code is as follows:

Activity_main.xml:

1 <Com.github.androidprogresslayout.ProgressLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:progresslayout= "Http://schemas.android.com/apk/res-auto"3 Android:id= "@+id/progresslayout"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent" >6 7     <TextView8         Android:id= "@+id/textview"9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" One android:textsize= "40SP" A android:layout_centerinparent= "true" /> -  - </Com.github.androidprogresslayout.ProgressLayout>

Mainactivity.java:

1  Packagecom.zzw.testandroidprogresslayout;2 3 Importcom.github.androidprogresslayout.ProgressLayout;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 ImportAndroid.os.Handler;8 ImportAndroid.os.Message;9 Importandroid.view.animation.Animation;Ten ImportAndroid.widget.TextView; One  A  Public classMainactivityextendsActivity { -  - @Override the     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -  +         FinalProgresslayout progresslayout =(progresslayout) Findviewbyid (r.id.progresslayout); -         FinalTextView TextView =(TextView) Findviewbyid (R.id.textview); +  AHandler Handler =NewHandler () { at @Override -              Public voidhandlemessage (Message msg) { -Textview.settext ("Test Complete"); -  -                 //switch back to normal display page - progresslayout.showcontent (); in             } -         }; to         //Start Loading ... Suppose starting from here a time-consuming operation will start, during this startup, the developer wants the user to take a break and wait ...  + progresslayout.showprogress (); -  the         //Suppose there is a time-consuming load of business logic that takes 5 seconds to complete.  *Handler.sendemptymessagedelayed (0, 5000); $     }Panax Notoginseng}

Load page masking time-consuming Operations task page--third party open source--androidprogresslayout

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.