ProgressBar of common Android components

Source: Internet
Author: User

The ProgressBar component is a progress bar that cannot be dragged, and he is able to display the current download progress, which contains a sub-progress bar, such as the buffering progress shown when playing streaming media.

The example is to control the increment and decrement of the main progress bar and the sub-progress bar by four keys respectively.

First, the layout file code:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:id= "@+id/linearlayout2"      android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     android:orientation= "vertical"     tools:context= "main.test_ ProgressBar. Mainactivity " >    <ProgressBar         Android:id= "@+id/progressbar1"         style= "? android:attr/ Progressbarstylehorizontal "        android:layout_width=" Fill_parent "         android:layout_height= "50DP"          android:max= "        android:progress=" 300 "      &Nbsp;  android:secondaryprogress= "        android": visibility= "visible"         android:background= "#ffffff00"  />         <!-- visibility is to set the progress bar visible, progress is the main progress bar and assigns an initial value of 300, Secondaryprogress is a sub-progress bar assigned an initial value of 400 -->    <linearlayout         android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"  >        <Button             android:id= "@+id/button1_1"              android:layout_width= "Wrap_content"              android:layout_height= "Wrap_content"               android:text= "@string/btn1_1"  />         <button            android:id= "@+id/button1_2"             android:layout_width= "Wrap_content"             android:layout_height= "Wrap_content"             android:text= "@string/btn1_2"  / >    </LinearLayout>    <LinearLayout         android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"  >        <button             android:id= "@+id/button2_1"        &nBsp;     android:layout_width= "Wrap_content"              android:layout_height= "Wrap_content"              android:text= "@string/btn2_1"  />         <button            android:id = "@+id/button2_2"             android:layout_width= "Wrap_content"             android:layout_height= " Wrap_content "            android:text=" @string/ Btn2_2 " />    </LinearLayout></LinearLayout>

Second on the Strings.xml file:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >test_progressbar</  string> <string name= "Btn1_1" > main minus </string> <string name= "Btn1_2" > main increment </string> <string Name= "Btn2_1" > VP </string> <string name= "Btn2_2" > sub-increment </string> </resources>

Again on Android source file:

package main.test_progressbar;import android.os.bundle;import  android.support.v7.app.actionbaractivity;import android.view.view;import  android.view.view.onclicklistener;import android.widget.button;import android.widget.progressbar; public class mainactivity extends actionbaractivity implements onclicklistener{     private progressbar pbar=null;    private button  btn1_1=null,btn1_2=null,btn2_1=null,btn2_2=null;        @ Override    protected void oncreate (bundle savedinstancestate)  {         super.oncreate (savedinstancestate);         setcontentview (R.layout.activity_main);                 pbar= (ProgressBar) Findviewbyid (r.id.progressBAR1);                 btn1_1= ( button) Findviewbyid (r.id.button1_1);         btn1_2= (Button) Findviewbyid (r.id.button1_2);         btn2_1= (Button) findViewById ( R.id.button2_1);         btn2_2= (Button) Findviewbyid (R.id.button2_2);                 btn1_1. Setonclicklistener (mainactivity.this);         btn1_2. Setonclicklistener (mainactivity.this);         btn2_1. Setonclicklistener (mainactivity.this);         btn2_2. Setonclicklistener (mainactivity.this);             }     @Override     public void onclicK (view arg0)  {        // TODO Auto-generated  Method stub        int n = arg0.getid ();//Get ID         switch  (n)  {//if it is the corresponding ID, increase or decrease the progress value          case r.id.button1_1: pbar.incrementprogressby ( -10); break;         case r.id.button1_2: pbar.incrementprogressby (Ten);  break;        case r.id.button2_1:  Pbar.incrementsecondaryprogressby ( -10); break;        case  R.id.button2_2: pbar.incrementsecondaryprogressby (Ten); break;         default: break;        }    }}

Finally, the test results are as follows:

ProgressBar of common Android components

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.