Application of Android Development--progressbar

Source: Internet
Author: User

1. Introduction

Progress is the progress bar for loading progress.

2. Build

The built interface increases the progress bar when pressing the + Key button, and the progress bar is reduced when the-button is pressed.

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools"
android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Example.progressbar.Activity1" >

<progressbar
android:id= "@+id/progressbar1"
style= "? Android:attr/progressbarstylehorizontal"
android:layout_width= "Fill_parent"
android:layout_height= "60DP"
android:progress= "Ten" //Set the initial length of the progress bar to 10%
android:layout_alignparentstart= "true"
android:layout_alignparenttop= "true"/>

<progressbar
android:id= "@+id/progressbar2"
style= "? Android:attr/progressbarstylelarge"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/progressbar1"
android:layout_centerhorizontal= "true"
android:layout_margintop= "47DP"/>

<button
android:id= "@+id/button1"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/progressbar2"
android:layout_margintop= "72DP"
android:layout_tostartof= "@+id/progressbar2"
android:text= "@string/bt1"/>

<button
android:id= "@+id/button2"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignbottom= "@+id/button1"
android:layout_toendof= "@+id/progressbar2"
android:text= "@string/bt2"/>
</RelativeLayout>

3. Code

Public class Activity1 extends Activity implements Onclicklistener{
Button b1,b2;
ProgressBar PB;  
@Override
Public void OnClick (View v) {
//To monitor the button, by ID to match
if (V.getid () ==r.id.button1) {
//Getporgress () Gets the length of the initial progress bar, multiplied by 2, increments one time, and then sets the progress bar by Setprogress ()
pb.setprogress ((int) (pb.getprogress ()));
        }
else{
pb.setprogress ((int) (pb.getprogress () *0.6));
        }       
    }

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.ACT1);
b1= (Button) Findviewbyid (R.id.button1);
B2= (Button) Findviewbyid (R.id.button2);
pb= (ProgressBar) Findviewbyid (R.ID.PROGRESSBAR1);
//Set listener
B1.setonclicklistener (this);
B2.setonclicklistener (this);
}

4. Effects

Application of Android Development--progressbar

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.