Android Simple combat tutorial--second words "two kinds of Progress bar"
Source: Internet
Author: User
<span id="Label3"></p><p><p>Click the button to simulate progress bar download progress, "download" complete progress bar Disappears.</p></p><p><p>The code is as Follows:</p></p><p><p><span style="font-size:24px">Xml:</span></p></p><p><p></p></p><pre code_snippet_id="1721751" snippet_file_name="blog_20160620_1_9951568" name="code" class="html"><pre code_snippet_id="1721751" snippet_file_name="blog_20160620_1_9951568" name="code" class="html"><?xml version= "1.0" encoding= "utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= "vertical" android:layout_width= "fill_parent" android:layout_height= "fill_parent" ><Tex TView android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "@string/hello" /><progressbarandroid:id= "@+id/firstbar" style= "android:attr/progressbarstylehorizontal" android:layout_ Width= "200dp" android:layout_height= "wrap_content" android:visibility= "gone"/><progressbarandroid:id= "@+id /secondbar "style="? android:attr/progressbarstyle "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:visibility=" gone "/><buttonandroid:id=" @+id/mybutton "android:layout_width=" wrap_ Content "android:layout_height=" wrap_content "android:text=" "begin"/></linearlayout> </pre></pre><span style="font-size:24px"><span style="font-size:24px">Activity:</span></span><p><p></p></p><p><p></p></p><pre code_snippet_id="1721751" snippet_file_name="blog_20160620_2_5033335" name="code" class="html">Package Ydl.progressbar;import Android.app.activity;import Android.os.bundle;import android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.progressbar;public Class Progressbartest extends activity {/** called when the activity is first created. *///declaration variable private ProgressBar Firstbar =null;private ProgressBar Secondbar = null;private Button MyButton = null;private int i = 0; @Override public void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Gets the object that represents the control according to the Control's id firstbar = (ProgressBar) findviewbyid (r.id.firstbar); Secondbar = (ProgressBar) Findviewbyid (r.id.secondbar); MyButton = (Button) Findviewbyid (r.id.mybutton); Mybutton.setonclicklistener (new Buttonlistener ()); } class Buttonlistener implements Onclicklistener{@Overridepublic void OnClick (View v) {if (i = = 0) {//set progress bar in visible state fi Rstbar.setvisibility (view.visibLE); Firstbar.setmax (150);//manually Set the maximum value, default is 100secondbar.setvisibility (view.visible);} else if (i < Firstbar.getmax ()) {//sets The current value of the main progress bar firstbar.setprogress (i);//sets The current value of the second progress bar firstbar.setsecondaryprogress ( i + 10);//because The default progress bar cannot display the status//secondbar.setprogress (i);} Else{//setting progress bar is not visible firstbar.setvisibility (view.gone); secondbar.setvisibility (view.gone);} i = i + 10;} } }</pre><br><br><p><p></p></p><p><p>Android Simple combat tutorial--second words "two kinds of Progress bar"</p></p></span>
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