android 自己定义水平和圆形progressbar 仅仅定义一些style就能够
效果图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
改动progressbar 让他满足自己的需求一般来说仅仅改动一下,progressbar的style就能够满足需求了:
activity代码:只显示一个布局而已
- package com.example.testcustomprogressbar;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- }
xml界面:
- <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="com.example.testcustomprogressbar.MainActivity" >
- <ProgressBar
- android:id="@+id/my_customprogressbar1"
- style="@style/mycustom_progressbar1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true" />
- <ProgressBar
- android:id="@+id/my_customprogressbar2"
- style="@style/mycustom_progressbar2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/my_customprogressbar1"
- android:layout_below="@+id/my_customprogressbar1"
- android:layout_marginTop="26dp" />
- <ProgressBar
- android:id="@+id/my_customprogressbar3"
- style="@style/mycustom_progressbar3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/my_customprogressbar2"
- android:layout_below="@+id/my_customprogressbar2"
- android:layout_marginTop="26dp" />
- <ProgressBar
- android:id="@+id/my_customprogressbar4"
- style="@style/mycustom_progressbar_hor"
- android:layout_width="200dp"
- android:layout_height="wrap_content"
- android:layout_below="@+id/my_customprogressbar3"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="22dp"
- android:max="100"
- android:progress="40"
- android:secondaryProgress="60" />
- <ProgressBar
- android:id="@+id/my_customprogressbar5"
- style="@style/mycustom_progressbar_hor2"
- android:layout_width="200dp"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/my_customprogressbar4"
- android:layout_below="@+id/my_customprogressbar4"
- android:layout_marginTop="26dp"
- android:max="100"
- android:progress="40"
- android:secondaryProgress="60" />
- </RelativeLayout>
第一种圆形progressbar 只让一个图片旋转起来:
style的代码:
- <style name="mycustom_progressbar1">
- <item name="android:indeterminateDrawable">@drawable/progressbar_ver_image</item>
- <item name="android:minHeight">30dp</item>
- <item name="android:minWidth">30dp</item>
- <item name="android:maxHeight">60dp</item>
- <item name="android:maxWidth">60dp</item>
- </style>
progressbar_ver_image的代码:
- <?
- xml version="1.0" encoding="utf-8"?>
- <!-- 定义一个旋转的动画 ,图片是我们自己定义的-->
- <rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/resizeapi"
- android:fromDegrees="0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toDegrees="360" >
- </rotate>
另外一种圆形progressbar 使用一个动画:
style:
- <style name="mycustom_progressbar2">
- <item name="android:indeterminateDrawable">@drawable/progressbar_ver_animation</item>
- <item name="android:minHeight">60dp</item>
- <item name="android:minWidth">60dp</item>
- <item name="android:maxHeight">100dp</item>
- <item name="android:maxWidth">100dp</item>
- </style>
progressbar_ver_animation的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:drawable="@drawable/ok1"
- android:duration="250"/>
- <item
- android:drawable="@drawable/ok2"
- android:duration="250"/>
- <item
- android:drawable="@drawable/ok3"
- android:duration="250"/>
- <item
- android:drawable="@drawable/ok4"
- android:duration="250"/>
- </animation-list>
第三种圆形progressbar 使用shape来构建drawable:
- <style name="mycustom_progressbar3">
- <item name="android:indeterminateDrawable">@drawable/progressbar_ver_shape</item>
- <item name="android:minHeight">60dp</item>
- <item name="android:minWidth">60dp</item>
- <item name="android:maxHeight">100dp</item>
- <item name="android:maxWidth">100dp</item>
- </style>
progressbar_ver_shape的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <!-- 定义一个旋转的动画 ,图片是我们自己定义的shape -->
- <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>
第四种: 横向progressbar 复制粘贴系统的style,然后改动:
- <?xml version="1.0" encoding="utf-8"?>
- <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="#ffff0000"
- android:centerColor="#ffff0000"
- android:centerY="0.75"
- android:endColor="#ffff0000"
- android:angle="270"
- />
- </shape>
- </item>
- <item android:id="@android:id/secondaryProgress">
- <clip>
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#800000ff"
- android:centerColor="#800000ff"
- android:centerY="0.75"
- android:endColor="#800000ff"
- android:angle="270"
- />
- </shape>
- </clip>
- </item>
- <item android:id="@android:id/progress"
- >
- <clip >
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#ff00ff00"
- android:centerColor="#ff00ff00"
- android:centerY="0.75"
- android:endColor="#ff00ff00"
- android:angle="270"
- />
- </shape>
- </clip>
- </item>
- </layer-list>
这样直接在progressbar中引用该style就能够满足需求了,当然我们也能够把progressbar background progress secondprogress都分别定义成一个drawable,然后使用:
background:
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <corners android:radius="5dip" />
- <gradient
- android:angle="270"
- android:centerColor="#ffff0000"
- android:centerY="0.75"
- android:endColor="#ffff0000"
- android:startColor="#ffff0000" />
- </shape>
progress:
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <corners android:radius="5dip" />
- <gradient
- android:angle="270"
- android:centerColor="#ff00ff00"
- android:centerY="0.75"
- android:endColor="#ff00ff00"
- android:startColor="#ff00ff00" />
- </shape>
secondprogress:
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <corners android:radius="5dip" />
- <gradient
- android:angle="270"
- android:centerColor="#800000ff"
- android:centerY="0.75"
- android:endColor="#800000ff"
- android:startColor="#800000ff" />
- </shape>
这个时候style中的代码就会清晰一点:
- <?
- xml version="1.0" encoding="utf-8"?
- >
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@android:id/background"
- android:drawable="@drawable/progressbar_hor_bg">
- </item>
- <item android:id="@android:id/secondaryProgress">
- <clip android:drawable="@drawable/progressbar_hor_second_progress" >
- </clip>
- </item>
- <item android:id="@android:id/progress">
- <clip android:drawable="@drawable/progressbar_hor_progress" >
- </clip>
- </item>
- <!-- progress 这个地方原作者写的是一个点9的图-->
- <!-- <item android:id="@android:id/progress">
- <clip>
- <nine-patch android:src="@drawable/progress_patch_galy" />
- </clip>
- </item> -->
- </layer-list>
嘿嘿..最后,做人要厚道:神一般男人的原博主博文连接http://blog.csdn.net/mad1989/article/details/38042875
对了,代码还是贴上来吧.总感觉在ide中直接看代码会更舒服一些:http://download.csdn.net/detail/u010399316/9000197
android 自己定义水平和圆形progressbar 仅仅定义一些style就能够的更多相关文章
- Android圆形图片--自己定义控件
Android圆形图片控件效果图例如以下: 代码例如以下: RoundImageView.java package com.dxd.roundimageview; import android.con ...
- Android 圆形ProgressBar风格设置
Android系统自带的ProgressBar风格不是很好,如果想自己设置风格的话,一般有几种方法.首先介绍一下第一种方法通过动画实现.在res的anim下创建动画资源loading.xml: < ...
- Android特效专辑(五)——自定义圆形头像和仿MIUI卸载动画—粒子爆炸
Android特效专辑(五)--自定义圆形头像和仿MIUI卸载动画-粒子爆炸 好的,各位亲爱的朋友,今天讲的特效还是比较炫的,首先,我们会讲一个自定义圆形的imageView,接着,我们会来实现粒子爆 ...
- 自定义的圆形ProgressBar
之前已经详细讲解过自定义控件的使用方式了.这里我单独把定以好的控件列出来. 之前定义的各式各样的ProgressBar http://www.cnblogs.com/tianzhijiexia ...
- 【Android自己定义View实战】之自己定义超简单SearchView搜索框
[Android自己定义View实战]之自己定义超简单SearchView搜索框 这篇文章是对之前文章的翻新,至于为什么我要又一次改动这篇文章?原因例如以下 1.有人举报我抄袭,原文链接:http:/ ...
- 实现android手机来电拦截系统页面弹出自定义页面特效
如何实现android手机来电拦截系统页面弹出自定义页面特效, 首先: 我们需要注册一个监听来电的广播PhoneStateReceiver 类:其次: 在onReceive里面我们获取an ...
- Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示
Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android实现圆角矩形,圆形或者椭圆等图形,一般通过自定义ImageView来实现,首先获取到图片的Bitmap,然后通过 ...
- Android改变系统自带环形ProgressBar的大小
MainActivity如下: package cc.testprogressbar; import android.os.Bundle; import android.app.Activity; / ...
- Android OpenGL ES(七)基本几何图形定义 .
在前面Android OpenGL ES(六):创建实例应用OpenGLDemos程序框架 我们创建了示例程序的基本框架,并提供了一个“Hello World”示例,将屏幕显示为红色. 本例介绍Ope ...
随机推荐
- 深度学总结:skip-gram pytorch实现
文章目录 skip-gram pytorch 朴素实现网络结构训练过程:使用nn.NLLLoss()batch的准备,为unsupervised,准备数据获取(center,contex)的pair: ...
- 洛谷——P1640 [SCOI2010]连续攻击游戏
P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...
- 洛谷—— P1268 树的重量
P1268 树的重量 构造类题目,看不出个所以然来... emmm,只好看题解: 只有两个点,那一条路径就是$ans$ 考虑三个点,那么$3$这个点相对于树上的路径(已经加入树上的边的距离) 为:$( ...
- SCOI2013 数数
题目描述 题解: 很玄学的一道数位$dp$,看了很多篇题解才懂. 直接挂$l$的题解. 代码: #include<cstdio> #include<cstring> #incl ...
- 01-mysql中的数据类型
mysql中的列数据类型:数值型.字符串类型.日期/时间类型3种 几种列类型描述使用了下述惯例:· M #表示最大显示宽度.最大有效显示宽度是255.· D #适用于浮点和定点类型,表示小数点后面的位 ...
- (11) openssl req(生成请求证书、私钥和自建CA)
伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA. 由于openssl req命令选项较多,所以先各举几个例子,再集中给出openssl req的选项说明.若已熟悉opens ...
- POJ 3122 pie (二分法)
Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have ...
- 项目如何发布到tomcat
在eclipse上export 出WAR file 然后将文件放到tomcat中的webapps 上即可.
- python019 Python3 File(文件) 方法
file 对象使用 open 函数来创建,下表列出了 file 对象常用的函数: 序号 方法及描述 1 file.close() 关闭文件.关闭后文件不能再进行读写操作. 2 file.flush() ...
- You Are the One (区间DP)
The TV shows such as You Are the One has been very popular. In order to meet the need of boys who ar ...