Step by step _ Android development course [23] _ ProgressBar (progress bar) on the user interface, android User Interface Design

Source: Internet
Author: User

Step by step _ Android development course [23] _ ProgressBar (progress bar) on the user interface, android User Interface Design

Focus on technology, enjoy life! -- QQ: 804212028.
Link: http://blog.csdn.net/y18334702058/article/details/44624305

  • Topic: ProgressBar on the user interface (progress bar)
    -
    Custom progress bar (Instance ):

Activity_main.xml:

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical"> <Button android: id = "@ + id/button" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "enable ProgressBar"/> <ProgressBar android: id = "@ + id/progressBar1" style = "? Android: attr/progressBarStyleLarge "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: progress =" 0 "android: visibility =" gone "/> <ProgressBar android: id = "@ + id/progressBar2" android: layout_width = "fill_parent" android: layout_height = "10dip" android: max = "100" android: progress = "0" android: secondaryProgress = "0" style = "? Android: attr/progressBarStyleHorizontal "android: progressDrawable =" @ drawable/progressbar_layer_list "android: background =" @ drawable/progressbar_box "android: visibility =" gone "/> </LinearLayout>

Create a drawable file under the res file, and then create progressbar_layer_list.xml under the drawable file.
Progressbar_layer_list.xml:

<?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item android:id="@android:id/background">        <clip>            <shape>                <corners android:radius="15dip" />                <gradient android:startColor="#00b7ee" android:endColor="#0075a9" android:angle="270" android:centerY="0.75"/>            </shape>        </clip>    </item>    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="15dip" />                <gradient android:startColor="#00b7ee" android:endColor="#0075a9" android:angle="270" android:centerY="0.75"/>            </shape>        </clip>    </item>    <item android:id="@android:id/progress">        <clip>            <shape>                <gradient android:startColor="#00b7ee" android:endColor="#0075a9" android:angle="270" android:centerY="0.25"/>                <corners android:radius="15dip"/>            </shape>        </clip>    </item></layer-list>

Progressbar_box image resources are as follows:

MainActivity. java source code:

Import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. progressBar; public class MainActivity extends Activity {private ProgressBar pro1, pro2; private Button button; private int count; @ Override public void onCreate (Bundle savedInsta NceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); button = (Button) findViewById (R. id. button); pro1 = (ProgressBar) findViewById (R. id. progressBar1); pro2 = (ProgressBar) findViewById (R. id. progressBar2); // set whether the progress bar is automatically running. If the value is false, pro1.setIndeterminate (false); pro2.setIndeterminate (false); button. setOnClickListener (new OnClickListener () {@ Override public void onC Lick (View arg0) {// set ProgressBar to visible State pro1.setVisibility (View. VISIBLE); pro2.setVisibility (View. VISIBLE); // TODO Auto-generated method stub new Thread (new Runnable () {public void run () {for (int I = 0; I <10; I ++) {try {count = I * 10; Thread. sleep (1000); if (count> = 100) {Message msg = new Message (); msg. what = 1; MainActivity. this. myHandler. sendMessage (msg);} else {Message msg = new Message (); msg. What = 2; MainActivity. this. myHandler. sendMessage (msg) ;}} catch (Exception e) {e. printStackTrace ();}}}}). start () ;}}) ;}handler myHandler = new Handler () {public void handleMessage (Message msg) {switch (msg. what) {case 1: Thread. currentThread (). interrupt (); break; case 2: if (! Thread. currentThread (). isInterrupted () {// change the current value of ProgressBar pro1.setProgress (count); pro2.setProgress (count ); // set a progress bar value in the title bar. // setProgress (count * 100 ); // set a progress bar value behind the title bar // setSecondaryProgress (count * 100);} break;} super. handleMessage (msg );}};}

Running result:

Focus on technology, enjoy life! -- QQ: 804212028.
Link: http://blog.csdn.net/y18334702058/article/details/44624305

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.