首页 技术 正文
技术 2022年11月9日
0 收藏 982 点赞 2,293 浏览 2077 个字

转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/52203533   点击打开链接

在Android初级教程里面,介绍了shape用法的理论知识,再来完成这个小案例将会变得非常简单哦。(欢迎学习阅读):http://blog.csdn.net/qq_32059827/article/details/52203347 点击打开链接

这一篇就针对这个知识点,完成一个自定义的彩色进度条。系统自带的环形进度条是黑白相间的,如果你不是色盲,肯定觉得那个进度条其丑无比!就有必要设计一下它的状态,让我们给她点”颜色”看看。

首先看一下要设计的进度条长什么样子,动态截图如下:

接下来就一步步的完成这个效果。

还是老样子,在drawable目录下建一个shape类型的文件。里面代码如下:

在style里面加入如下代码:

<style name="ProgressBar">
<item name="android:indeterminateOnly">true</item>
<item name="android:indeterminateDrawable">@drawable/progressstyleshape</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:indeterminateDuration">3500</item>
<item name="android:minWidth">60dip</item>
<item name="android:maxWidth">60dip</item>
<item name="android:minHeight">60dip</item>
<item name="android:maxHeight">60dip</item>
<item name="android:mirrorForRtl">false</item>
</style>

在style里面引入了shape,drawable/progressstyleshape.xml文件里面的代码如下:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" > <!--
封装一个动画
0~360°旋转、锚点位于中心
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="10"
android:useLevel="false" >
<gradient
android:endColor="#0000ff"
android:startColor="#ff0000"
android:type="sweep" />
<!--
android:shape="ring"系统默认矩形,这里修改为环形
android:innerRadiusRatio=""表示内半径比:矩形宽度/内半径比 = 圆环的半径,这个值越大,整个环形越小
android:thicknessRatio="10"表示厚度比:矩形宽度/厚度比 = 环形的厚度。这个值越大,线条厚度越细
android:useLevel="false"表示让进度条环形不切分,完全显示,不是仅仅旋转一次
gradint表示颜色的渐变,颜色的过度
android:type="sweep" 表示扫射的效果,给人一种颜色慢慢过度的感觉 --> </shape></rotate>

然后再布局文件里面引入样式:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <ProgressBar
android:layout_centerInParent="true"
style="@style/ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/></RelativeLayout>

运行程序截图:

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,112
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,585
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922