、、、、、、、、、、、、、、、、、、、第一种、、、、、、、、、、、、、、、、、、
1.首先,我们要准备我们自己需要的转圈圈的图或者进度条的图片,并且命名为
progressbar_indeterminate1
progressbar_indeterminate2
progressbar_indeterminate3 ...等。
然后写一个xml文件,如下:
- <?xml version="1.0" encoding="utf-8"?>
- <animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <item android:drawable="@drawable/progressbar_indeterminate1" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate2" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate3" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate4" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate5" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate6" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate7" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate8" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate9" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate10" android:duration="200" />
- <item android:drawable="@drawable/progressbar_indeterminate11" android:duration="200" />
- </animation-list>
2.在我们的Progressbar控件中这么配置我们刚才定义好的样式:
- <ProgressBar
- android:indeterminateDrawable="@drawable/progressbar_indeterminate"
- android:id="@+id/progressBar1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </ProgressBar>
3.OK,大功告成!!
4.最后总结一下:
我们应该多看一下系统的那些样式,看看google的工程师们是怎么去定义这些东西的,从中我们可以学到很多东西。
顺便说一下,虽然本文讲的Progressbar的样式,但是,我们完全可以把这个设置到一个需要设置动画的页面布局上,比如我们的程序在进入的时候需要播放一个动画,宣传公司的某个产品或者说提示用户怎么操作我们的程序以及一些快捷键什么的,完全可以这么去配置,而不再需要一个ImageView对象和AnimationDrawable对象,来通过start()来播放我们的动画,是不是很方便呐!!哈哈!!
、、、、、、、、、、、、、、、、、、、第二种、、、、、、、、、、、、、、、、、、
1.在drawable目录下新建一个progress_drawable_large.xml文件,如是写;
可查看源码:\frameworks\base\core\res\res\drawable\progress_large.xml
- <?xml version="1.0" encoding="utf-8"?>
- <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/bg_loading_1"
- android:pivotX="50%"
- android:pivotY="50%" />
说明:bg_loading_1.png便是我们要设置的转圈圈的图片,一张便可。是不是比上面的节省资源吖~
2.应用到控件当中去,如是写:
- <ProgressBar
- android:indeterminateDrawable="@drawable/progress_drawable_large"
- android:indeterminateOnly="true"
- android:indeterminateDuration="500"
- android:indeterminateBehavior="repeat"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></ProgressBar>
说明:indeterminateDuration 设置转动时间
3.没有第三步,oker,大功告成了 ,哈哈,简单吧~
以上方法纯参照系统源码学习:
附:系统部分源码
111.系统中设置长条形进度条进度背景的progress_horizontal.xml:
可查看源码:...frameworks\base\core\res\res\drawable\progress_horizontal.xml
- <?xml version="1.0" encoding="utf-8" ?>
- - <!-- Copyright (C) 2008 The Android Open Source Project
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- - <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- - <item android:id="@android:id/background">
- - <shape>
- <corners android:radius="5dip" />
- <gradient android:startColor="#ff9d9e9d" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:angle="270" />
- </shape>
- </item>
- - <item android:id="@android:id/secondaryProgress">
- - <clip>
- - <shape>
- <corners android:radius="5dip" />
- <gradient android:startColor="#80ffd300" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:angle="270" />
- </shape>
- </clip>
- </item>
- - <item android:id="@android:id/progress">
- - <clip>
- - <shape>
- <corners android:radius="5dip" />
- <gradient android:startColor="#ffffd300" android:centerColor="#ffffb600" android:centerY="0.75" android:endColor="#ffffcb00" android:angle="270" />
- </shape>
- </clip>
- </item>
- </layer-list>
应用到控件中:
- <ProgressBar
- android:progressDrawable="@drawable/progress_horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></ProgressBar>
222.系统中几种常见的样式:
可查看源码...\frameworks\base\core\res\res\values\styles.xml
- <style name="Widget.ProgressBar">
- <item name="android:indeterminateOnly">true</item>
- <item name="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
- <item name="android:indeterminateBehavior">repeat</item>
- <item name="android:indeterminateDuration">3500</item>
- <item name="android:minWidth">48dip</item>
- <item name="android:maxWidth">48dip</item>
- <item name="android:minHeight">48dip</item>
- <item name="android:maxHeight">48dip</item>
- </style>
- - <style name="Widget.ProgressBar.Large">
- <item name="android:indeterminateDrawable">@android:drawable/progress_large_white</item>
- <item name="android:minWidth">76dip</item>
- <item name="android:maxWidth">76dip</item>
- <item name="android:minHeight">76dip</item>
- <item name="android:maxHeight">76dip</item>
- </style>
- - <style name="Widget.ProgressBar.Small">
- <item name="android:indeterminateDrawable">@android:drawable/progress_small_white</item>
- <item name="android:minWidth">16dip</item>
- <item name="android:maxWidth">16dip</item>
- <item name="android:minHeight">16dip</item>
- <item name="android:maxHeight">16dip</item>
- </style>
- - <style name="Widget.ProgressBar.Inverse">
- <item name="android:indeterminateDrawable">@android:drawable/progress_medium</item>
- </style>
- - <style name="Widget.ProgressBar.Large.Inverse">
- <item name="android:indeterminateDrawable">@android:drawable/progress_large</item>
- </style>
- - <style name="Widget.ProgressBar.Small.Inverse">
- <item name="android:indeterminateDrawable">@android:drawable/progress_small</item>
- </style>
- - <style name="Widget.ProgressBar.Small.Title">
- <item name="android:indeterminateDrawable">@android:drawable/progress_small_titlebar</item>
- </style>
- - <style name="Widget.ProgressBar.Horizontal">
- <item name="android:indeterminateOnly">false</item>
- <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
- <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
- <item name="android:minHeight">20dip</item>
- <item name="android:maxHeight">20dip</item>
- </style>