Android Hands-on Tutorial The second one is simple to achieve two kinds of progress bar effect _android

Source: Internet
Author: User
Tags visibility

The example of this article to achieve the Click button to simulate the progress bar download progress, "download" The completion of the progress bar disappeared for your reference, the specific contents are as follows

The code is as follows:
Xml:

 <?xml version= "1.0" encoding= "Utf-8"?> <linearlayout "xmlns:android=" Schemas.android.com/apk/res/android "android:orientation=" vertical "android:layout_width=" Fill_parent "Android: layout_height= "Fill_parent" > <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_conte" NT "android:text=" @string/hello "/> <progressbar android:id=" @+id/firstbar "style="? Android:attr/progressba Rstylehorizontal "android:layout_width=" 200DP "android:layout_height=" wrap_content "android:visibility=" Gone "/>" 
; <progressbar android:id= "@+id/secondbar" style= "Android:attr/progressbarstyle" android:layout_width= Content "android:layout_height=" wrap_content "android:visibility=" Gone "/> <button android:id=" @+id/myButto N "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" Begin "/> </Linea Rlayout> 

Activity:

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; The public class Progressbartest extends activity {/** called the ' when the ' is the ' The activity ' is a.//declare variable private Pro 
 Gressbar 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 representing the control Firstbar = (ProgressBar) Findviewbyid (R.id.firstbar), based on the ID of the control; 
  Secondbar = (ProgressBar) Findviewbyid (R.id.secondbar); 
  MyButton = (Button) Findviewbyid (R.id.mybutton); 
 Mybutton.setonclicklistener (New Buttonlistener ()); 
   Class Buttonlistener implements onclicklistener{@Override public void OnClick (View v) {if (i = = 0) {//Set the progress bar in the visible state fiRstbar.setvisibility (view.visible); 
   Firstbar.setmax (150);//Manually set the maximum value, the default is Secondbar.setvisibility (view.visible); 
    else if (I < Firstbar.getmax ()) {//Set the current value of the Master progress bar firstbar.setprogress (i); 
    Set 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{//Set the progress bar in an invisible state firstbar.setvisibility (View.gone); 
   Secondbar.setvisibility (View.gone); 
  } i = i + 10; } 
   
 } 
  
}

  above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud-dwelling community.

Related Article

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.