自定义圆形的ProgressBar
1.自定义圆形的ProgressBar
效果图:
圆形ProgressBar的样式主要有以下几个,我们这里以progressBarStyleLarge为例进行样式的修改,其他的类似。
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"/>
首先看一下style="?android:attr/progressBarStyleLarge"的源码,在\frameworks\base\core\res\res\values\styles.xml

<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>

看到这一行<item name="android:indeterminateDrawable">@android:drawable/progress_large_white</item>有木有,我们去看一下它的源码,在\frameworks\base\core\res\res\drawable\progress_large_white.xml
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_white_76"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360" />
看到这一行 android:drawable="@drawable/spinner_white_76" 我们就明白了,原来它在这里放了一张图片,进行旋转。
接下来我定义自己的ProgressBarStyle:
首先我们先找一张图片加入我们的项目中(如一开始的效果图片),然后在drawable下新建progress_large.xml文件

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_large"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />

在 \value\style.xml中定义myProgressBarStyleLarge

<style name="myProgressBarStyleLarge" >
<item name="android:indeterminateDrawable">@drawable/progress_large</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>

最后在ProgressBar中使用我们自己定义的style,android:indeterminateDuration="700"指定图片旋转的速度,这样我们就可以根据自己的需要来定义ProgressBar的样式。
<ProgressBar
style="@style/myProgressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDuration="700" />
2.上面是通过一张图片填充android:indeterminateDrawable,我们也可以定义一个动画或者自定义颜色来实现,跟图片的用法一样:
定义res/anim/progress_large_loading.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="100" android:drawable="@drawable/loading_1" />
<item android:duration="100" android:drawable="@drawable/loading_2" />
<item android:duration="100" android:drawable="@drawable/loading_3" />
<item android:duration="100" android:drawable="@drawable/loading_4" />
<item android:duration="100" android:drawable="@drawable/loading_5" />
<item android:duration="100" android:drawable="@drawable/loading_6" />
</animation-list>

在我们定义的style中引入<item name="android:indeterminateDrawable">@anim/progress_large_loading</item>
定义res/drawable/progress_large_shape.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" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<gradient
android:centerColor="#FFFFFF"
android:centerY="0.50"
android:endColor="#1E90FF"
android:startColor="#000000"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>

在我们定义的style中引入<item name="android:indeterminateDrawable">@drawable/progress_large_shape</item>
自定义圆形的ProgressBar的更多相关文章
- Android简单自定义圆形和水平ProgressBar
ProgressBar简介 继承于View类,直接子类有AbsSeekBar和ContentLoadingProgressBar,其中AbsSeekBar的子类有SeekBar和RatingBar,可 ...
- 自定义圆形控件 RoundImageView
1.自定义圆形控件 RoundImageView package com.ronye.CustomView; import android.content.Context; import androi ...
- 自定义圆形控件RoundImageView并认识一下attr.xml
今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...
- Android 自定义View修炼-实现自定义圆形、圆角和椭圆ImageView(使用Xfermode图形渲染方法)
一:简介: 在上一篇<Android实现圆形.圆角和椭圆自定义图片View(使用BitmapShader图形渲染方法)>博文中,采用BitmapShader方法实现自定义的圆形.圆角等自定 ...
- 自定义圆形imageview
import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader ...
- CircleImageView自定义圆形控件的使用
1.自定义圆形控件github地址: https://github.com/hdodenhof/CircleImageView 主要的类: package de.hdodenhof.circleima ...
- Android特效专辑(五)——自定义圆形头像和仿MIUI卸载动画—粒子爆炸
Android特效专辑(五)--自定义圆形头像和仿MIUI卸载动画-粒子爆炸 好的,各位亲爱的朋友,今天讲的特效还是比较炫的,首先,我们会讲一个自定义圆形的imageView,接着,我们会来实现粒子爆 ...
- Windows Phone开发手记-WinRT下自定义圆形ItemsControl
这里的ItemsControl指的是Xaml里的集合控件,包括ListView,GridView等,此篇博客主要参考MSDN Blog的一篇文章,具体出处为:http://blogs.msdn.com ...
- 自定义圆形控件RoundImageView并认识一下attr
昨天我们学习了自定义带图片和文字的ImageTextButton,非常简单,我承诺给大家要讲一下用自定义属性的方式学习真正的实现自定义控件,在布局文件中使用属性的方式就需要用到attr.xml这个文件 ...
随机推荐
- navicat连接centos7上mysql:2003-Can't connect to MySQL server (10060)
问题解决步骤: 1.参考http://jingyan.baidu.com/article/95c9d20dac9040ec4f75617a.html,发现是防火墙未关闭: 2.关闭并禁止firewal ...
- jquery插件之一些小链接
1.验证 验证的插件: http://parsleyjs.org/ http://jqueryvalidation.org/2.前端UI 首页动态图片的插件:http://bxslider.com/ ...
- Java对象引用和对象赋值
关于对象与引用之间的一些基本概念. 初学Java时,在很长一段时间里,总觉得基本概念很模糊.后来才知道,在许多Java书中,把对象和对象的引用混为一谈.可是,如果我分不清对象与对象引用,那实在没法很好 ...
- Java中 StringTokenizer 的用法
一.StringTokenizer 1.1 StringTokenizer简介及其构造函数的三种形式: StringTokenizer类是字符串分割解析类型,其属于java.util包,在使用之前需要 ...
- JavaScript处理null、undefined和空值
最近一直在写前端,在使用jquery的ajax请求然后处理返回值的时候,经常会遇到返回值为undefined或者"null"的情况,很是头疼,而返回接口是来自于其他公司的,所以这种 ...
- PostgreSQL>窗口函数的用法
PostgreSQL之窗口函数的用法 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9311281.html PostgreSQL的高级特性本准备三篇的(递归. ...
- Spring Cloud微服务笔记(五)Feign
Feign 一.Feign概述 Feign是一个声明式的Web Service客户端.在Spring Cloud 中使用Feign,可以做到 使用HTTP请求访问远程服务,就像调用本地方法一样,同时它 ...
- 记一次非常规方法对接硬件设备(Grason Stadler GSI 61)
Grason Stadler GSI 61 电测听设备 (写下设备的名字, 希望别人遇坑可以搜到) 对接说明 设备厂家提供自带的软件,但是没有找到接口说明.我们需要获取设备发送过来的数据. 厂家提供的 ...
- 51nod1007-正整数分组(dp)
题目 :http://www.51nod.com/Challenge/Problem.html#!#problemId=1007 大意就是给一堆正整数,分成和最接近的两组. 最开始没什么想法,2^n尝 ...
- VMware ESXi 6.5 安装
1.1下载esxi镜像 此处我使用的版本是:VMware-VMvisor-Installer-6.5.0-4564106.x86_64 1.2新建一个虚拟机,硬件兼容性处选择ESXI6.5 硬盘40g ...