Android uses code to display ProgressDialog and ProgressBar in the middle of the screen

Source: Internet
Author: User
<span id="Label3"></p><pre><span style="color: #000000;">package <span style="color: #000000;">cc.testprogressdialog;import android.os.bundle;import Android.view.gravity;import android.view.View; Import Android.view.viewgroup.layoutparams;import Android.widget.framelayout;import android.widget.LinearLayout; Import Android.widget.progressbar;import Android.app.activity;import Android.app.progressdialog;import android.content.Context;</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;">* <span style="color: #008000;">* Demo Description: * Use code to display ProgressDialog and ProgressBar in the middle of the screen * reference: * 1</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://blog.csdn.net/lfdfhl/article/details/18913435</span></span><span style="color: #008000;"><span style="color: #008000;">* 2</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://blog.csdn.net/lfdfhl/article/details/9299075</span></span><span style="color: #008000;"><span style="color: #008000;">* 3</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://rocye.iteye.com/blog/1258936</span></span><span style="color: #008000;"><span style="color: #008000;">* Thank you very much * * If you add a control dynamically in a linear layout, and you want the control to be centered in the Layout. * can also be used in a similar way in the Createprogressbar () method *</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span><span style="color: #000000;"><span style="color: #000000;">Mainactivity extends Activity {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span><span style="color: #000000;"><span style="color: #000000;">Context mcontext; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span><span style="color: #000000;"><span style="color: #000000;">ProgressBar mprogressbar; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span><span style="color: #000000;"><span style="color: #000000;">ProgressDialog mprogressdialog; @Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">protected</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Show ProgressBar</span></span><span style="color: #000000;"><span style="color: #000000;">Createprogressbar (); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Show ProgressDialog</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Createprogressdialog ();</span></span><span style="color: #000000;"><span style="color: #000000;"> } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">Createprogressbar () {mcontext</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">Final Parent layout of the entire activity layout, See Resources</span></span>Framelayout rootframelayout=<span style="color: #000000;"><span style="color: #000000;">(framelayout) Findviewbyid (android. r.id.content); Framelayout.layoutparams Layoutparams</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Framelayout.layoutparams (layoutparams.wrap_content, layoutparams.wrap_content); Layoutparams.gravity</span></span>=<span style="color: #000000;"><span style="color: #000000;">gravity.center; Mprogressbar</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">ProgressBar (mcontext); Mprogressbar.setlayoutparams (layoutparams); Mprogressbar.setvisibility (view.visible); Rootframelayout.addview (mprogressbar); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">createprogressdialog () {mcontext</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">; Mprogressdialog</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">ProgressDialog (mcontext); Mprogressdialog.setmessage (</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">... Could you wait a moment, please</span> ?</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); Mprogressdialog.show (); }}</span></span></pre><p><p></p></p><p><p>Android uses code to display ProgressDialog and ProgressBar in the middle of the screen</p></p></span>

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.