Android ProgressBar Manual control Start and stop

Source: Internet
Author: User

There is a need for these two days, click the button to extract the compressed package from the SD card, and read the contents of the TXT document inside the package, and then display it in streets. After all, IO operations are time consuming, and if the file size is large it can take a while. So, when processing the data can give a progress. Our usual practice is to click on the button to pop up a box or load the progress bar, and so after the end of data processing, and then let the dialog box disappear.

But now the requirement is that with a layout, the left side shows the refresh list, and the ProgressBar on the right. Then the problem came, ProgressBar display is very large, and after opening it has been rotating, uncontrollable. So let's solve the two problems.

First question: Control the size and style of the ProgressBar

First, create a style style, set the width height, and the picture, as follows:

<StyleName="Progresscircle" > <ItemName="Android:indeterminatedrawable" > @drawable/IC_REFRESH_GREY_600_24DP</Item><Itemname= "android:minwidth" >25dp</< Span class= "Hljs-name" >item> <item  Name= "android:minheight" >25dp</ item> <item name=  "android:maxwidth" >60dp</item > <item name=  "android:maxheight" >60dp</item ></STYLE>        

Then, write an XML file Progressbar_circle.xml, set the ProgressBar rotation effect.

 <?xml version=  "1.0" Encoding= "utf-8" ?><rotate xmlns:android=  "http://schemas.android.com/apk/res/android" android:drawable = "@drawable/IC_REFRESH_GREY_600_24DP" android:fromdegrees=< Span class= "hljs-string" > "0" android:pivotx= "50%" android:pivoty=" 50% "android:todegrees= ">
                      
                       </
                       ROTATE>  
                         

Here, the size is fixed, the rotation effect also has.

Second problem: Manual control of start and stop of rotation

At the beginning, set setindeterminatedrawable and setprogressdrawable as the defined XML file to start turning.

At the end, set the setindeterminatedrawable and setprogressdrawable as fixed images and stop the rotation.

/** * 开始刷新动画 */public void startRefresh() { progressbar_refresh.setIndeterminateDrawable(getResources().getDrawable( R.drawable.progressbar_circle)); progressbar_refresh.setProgressDrawable(getResources().getDrawable( R.drawable.progressbar_circle));}/** * 停止刷新动画 */public void stopRefresh() { progressbar_refresh.setIndeterminateDrawable(getResources().getDrawable( R.drawable.ic_refresh_grey_600_24dp)); progressbar_refresh.setProgressDrawable(getResources().getDrawable( R.drawable.ic_refresh_grey_600_24dp));}

Above.

Android ProgressBar Manual control start and stop

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.