各位看官们大家好,上一回中咱们说的是Android中ProgressBar原理与总结的例子,这一回咱们继续说该例子。闲话休提,言归正转。让我们一起Talk Android吧!
看官们,我们在上一章回中分析了进度条默认的style文件,这一回中我们将分析我们在前面章回中使用的style文件:Widget.ProgressBar.Horizontal
,它也是系统提供的一种style。此外,系统还提供了其它的style,不过它们和默认的style文件类似,因此就不分析了。大家如果想分析的话,可以到frameworks/base/core/res/res/values/styles.xml
文件中去查看,这里包含了进度条所有的style,另外,其中进度条的两个子类:SeekBar和RatingBar
也使用了style,这些style也在此文件中。下面我们来看看Widget.ProgressBar.Horizontal
的源代码。
<style name="Widget.ProgressBar.Horizontal">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">@drawable/progress_horizontal</item>
<item name="indeterminateDrawable">@drawable/progress_indeterminate_horizontal</item>
<item name="minHeight">20dip</item>
<item name="maxHeight">20dip</item>
<item name="mirrorForRtl">true</item>
</style>
从源代码中可以看到,它使用Drawable文件:progress_horizontal
和progress_indeterminate_horizontal
。这两个Drawable文件位于frameworks/base/core/res/res/values/drawable/
目录下。
我们先看看progress_horizontal
的源代码:
<?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>
它使用了图层包含三个图层,每个图层中使用了多种标签,不过和我们在前面章回中自定义Drawable文件类似,具体的细节就不说明了。
接下来看看progress_indeterminate_horizontal的源代码:
<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" />
</animation-list>
从源代码中可以看到,它使用了动画,动画中使用了三个图片,这些图片位于frameworks/base/core/res/res/drawable-mdpi目录下。
看官们,到此为止我们分析了进度条使用了两种style文件,从中可以看到很多图形相关的内容都是通过Drawable来实现的,因此如果想实现各种漂亮的进度条,需要从Drawable资源文件入手,当然了进度条本质上是一种自定义的View(这点我们在上一回中也说过),除了Drawable文件外,View相关的方法也需要处理,不然也无法在程序中运行。
各位看官,关于Android中ProgressBar原理与总结的例子咱们就介绍到这里,欲知后面还有什么例子,且听下回分解!