The ProgressBar of Android common controls

Source: Internet
Author: User
Tags visibility

ProgressBar is a visual indicator of the progress of some operations, rendering the operation's progress to the user, and it has a minor progress bar to display intermediate progress, such as the progress of the buffer playing in streaming media. A progress bar can also be uncertain about its progress. In an indeterminate mode, the progress bar displays a looping animation. If you do not set the style of the progress bar, the default is to determine the progress style, the screen will not change with the progress of the different.

The ProgressBar style has the following four kinds:

android:progressBarStyle:默认进度条样式,不确定模式
android:progressBarStyleHorizontal:水平进度条样式
android:progressBarStyleLarge :大号进度条样式,也是不确定进度模式
android:progressBarStyleSmall :小号进度条样式,也是不确定进度模式

Common methods:

int getMax():返回这个进度条的范围的上限
int getProgress():返回进度
int getSecondaryProgress():返回次要进度
void incrementProgressBy(int diff):指定增加的进度
boolean isIndeterminate():指示进度条是否在不确定模式下
void setIndeterminate(boolean indeterminate):设置不确定模式下
void setVisibility(int v):设置该进度条是否可视

Example: Create a new Android application project and add four ProgressBar controls to the Main.xml file, followed by the default progress bar style, horizontal progress bar style, large progress bar style, and small progress bar style. Add a button, and the first click is to show the progress bar, then each click, the progress bar to increase a certain progress. Hides the progress bar when the progress of the last progress bar reaches its maximum.

Main.xml

<xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_pare NT "> <textview android:layout_width=" fill_parent "android:layout_height=" Wrap_content "Andro id:text= "@string/hello"/> <!--add four progress bar controls, android:visibility= the "Gone" setting progress bar is not visible. Use the style= "? android:attr/***" statement to set the style of the progress bar to the normal indeterminate style, the horizontal progress bar style, the large progress bar style, and the small progress bar style. --> <progressbar android:id= "@+id/firstbar android:layout_width=" wrap_content "android:layout_height="

Wrap_content "android:visibility=" Gone "style="? 
		

Android:attr/progressbarstyle "/> <progressbar android:id=" @+id/secondbar "android:layout_width=" 200DP "

android:layout_height= "30DP" android:visibility= "Gone" style= "? Android:attr/progressbarstylehorizontal "/> <progrEssbar android:id= "@+id/thirdbar" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"

Android:visibility= "Gone" style= "? Android:attr/progressbarstylelarge "/> <progressbar android:id=" @+id/fourthbar "Android:layout_width=" W

Rap_content "android:layout_height=" wrap_content "android:visibility=" Gone "style="? Android:attr/progressbarstylesmall "/> <button android:id=" @+id/button "android:layout_width=" Wrap_conten T "android:layout_height=" wrap_content "android:text= Show progress"/> </LinearLayout>

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.