Android implementation ProgressBar progress bar component

Source: Internet
Author: User

Android implementation ProgressBar progress bar component:

(Note: Horizontal that progress bar to android4.0 above version support, namely minimum (android:minsdkversion= "14") support)

Layout: Layout/activity_main.xml

<linearlayout 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:orientation= "Vertical"
>


<progressbar
Android:id= "@+id/pb1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Style= "@android: Style/widget.progressbar"/>
<progressbar
Android:id= "@+id/pb2"
Android:layout_width= "Match_parent"
android:layout_height= "50DP"
Style= "@android: Style/widget.progressbar.horizontal"
android:max= "100"
Android:progress= "/>"
<button
android:layout_margintop= "50DP"
Android:id= "@+id/bt1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "Download File"
/>
</LinearLayout>

Java code:

Package com.litsoft.main;


Import android.support.v7.app.ActionBarActivity;
Import Android.os.Bundle;
Import android.os.Process;
Import Android.os.SystemClock;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ProgressBar;


public class Mainactivity extends Actionbaractivity {
Private ProgressBar Gressbar;
Private Button BT;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Init ();
Setlistener ();
}


private void Setlistener () {
TODO auto-generated Method Stub
Bt.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
New Thread () {
@Override
public void Run () {
TODO auto-generated Method Stub
for (int i=0;i<100;i++) {
Gressbar.setprogress (i);
Systemclock.sleep (2000);
}
}
}.start ();
}
});
}


private void init () {
TODO auto-generated Method Stub
Gressbar = (ProgressBar) Findviewbyid (R.ID.PB2);
Gressbar.setprogress (0);
BT = (Button) Findviewbyid (R.ID.BT1);
}


}

Effect:

650) this.width=650; "src=" http://img.blog.csdn.net/20141123142823612 "/>

This article from "Follow the heart of the other side" blog, declined reprint!

Android implementation ProgressBar progress bar component

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.