Progress bar of the android Control

Source: Internet
Author: User

Progressbar is the progress bar of Android. Experience

 

Source code download

The following describes progressbar in detail.

I. Description

In the progress of some operationsA visual indicator that shows you the progress of the operation,It also has a secondary progress bar to display the intermediate progress, such as the progress in the buffer area of streaming media playback.A progress bar cannot be determined.In uncertain mode, the progress bar displays a circular animation.This mode is often used in applications.ProgramThe length of a task is unknown.

Ii. Important XML attributes

Android: progressbarstyle: Default progress bar style

Android: progressbarstylehorizontal: horizontal style

 

Iii. Important Methods

Getmax():Returns the maximum range of the progress bar.

Getprogress(): Return the progress

Getsecondaryprogress(): Returns the secondary progress.

Incrementprogressby(INT diff): Specifies the increase progress.

Isindeterminate(): Indicates whether the progress bar is in uncertain mode.

Setindeterminate(Boolean indeterminate): sets the uncertain mode.

Setvisibility(Int v): sets whether the progress bar is visible.

4. Important Events

Onsizechanged(Int w, int H, int oldw, int oldh): this event is triggered when the progress value changes.

V. Instances

1. layout File

<? XML version = "1.0" encoding = "UTF-8"?>


Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">


style = "? Android: ATTR/progressbarstylehorizontal "
Android: layout_width = "200dip"
Android: layout_height = "wrap_content"
Android: max = "100"
Android: progress = "50"
Android: secondaryprogress = "75"/>

<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Default progress bar"/>

<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">


Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: TEXT = "decrease"/>

<Button Android: Id = "@ + ID/increase"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "add"/>

</Linearlayout>

<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Custom progress bar"/>

<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">


Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: TEXT = "second decrease"/>

<Button Android: Id = "@ + ID/increase_secondary"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "added second"/>

</Linearlayout>

</Linearlayout>

 

2. JavaCode

Package wjq. widgetdemo;

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. window;
Import Android. widget. Button;
Import Android. widget. progressbar;

Public class progressbardemo extends activity {

/* (Non-javadoc)
* @ See Android. App. Activity # oncreate (Android. OS. Bundle)
*/
@ Override
Protected void oncreate (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. oncreate (savedinstancestate );

Requestwindowfeature (window. feature_progress );
Setcontentview (R. layout. probarpage );
Setprogressbarvisibility (true );

Final progressbar progresshorizontal = (progressbar) findviewbyid (R. Id. progress_horizontal );
Setprogress (progresshorizontal. getprogress () * 100 );
Setsecondaryprogress (progresshorizontal. getsecondaryprogress () * 100 );

Button button = (button) findviewbyid (R. Id. increase );
Button. setonclicklistener (New button. onclicklistener (){
Public void onclick (view v ){
Progresshorizontal. incrementprogressby (1 );
// Title progress is in range 0 .. 10000
Setprogress (100 * progresshorizontal. getprogress ());
}
});

Button = (button) findviewbyid (R. Id. Decrease );
Button. setonclicklistener (New button. onclicklistener (){
Public void onclick (view v ){
Progresshorizontal. incrementprogressby (-1 );
// Title progress is in range 0 .. 10000
Setprogress (100 * progresshorizontal. getprogress ());
}
});

Button = (button) findviewbyid (R. Id. increase_secondary );
Button. setonclicklistener (New button. onclicklistener (){
Public void onclick (view v ){
Progresshorizontal. incrementsecondaryprogressby (1 );
// Title progress is in range 0 .. 10000
Setsecondaryprogress (100 * progresshorizontal. getsecondaryprogress ());
}
});

Button = (button) findviewbyid (R. Id. decrease_secondary );
Button. setonclicklistener (New button. onclicklistener (){
Public void onclick (view v ){
Progresshorizontal. incrementsecondaryprogressby (-1 );
// Title progress is in range 0 .. 10000
Setsecondaryprogress (100 * progresshorizontal. getsecondaryprogress ());
}
});

}

}

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.