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