效果图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

改动progressbar 让他满足自己的需求一般来说仅仅改动一下,progressbar的style就能够满足需求了:

activity代码:只显示一个布局而已

  1. package com.example.testcustomprogressbar;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.Menu;
  6. import android.view.MenuItem;
  7.  
  8. public class MainActivity extends Activity {
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. }
  15. }

xml界面:

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context="com.example.testcustomprogressbar.MainActivity" >
  6.  
  7. <ProgressBar
  8. android:id="@+id/my_customprogressbar1"
  9. style="@style/mycustom_progressbar1"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:layout_alignParentTop="true"
  13. android:layout_centerHorizontal="true" />
  14.  
  15. <ProgressBar
  16. android:id="@+id/my_customprogressbar2"
  17. style="@style/mycustom_progressbar2"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_alignLeft="@+id/my_customprogressbar1"
  21. android:layout_below="@+id/my_customprogressbar1"
  22. android:layout_marginTop="26dp" />
  23.  
  24. <ProgressBar
  25. android:id="@+id/my_customprogressbar3"
  26. style="@style/mycustom_progressbar3"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_alignLeft="@+id/my_customprogressbar2"
  30. android:layout_below="@+id/my_customprogressbar2"
  31. android:layout_marginTop="26dp" />
  32.  
  33. <ProgressBar
  34. android:id="@+id/my_customprogressbar4"
  35. style="@style/mycustom_progressbar_hor"
  36. android:layout_width="200dp"
  37. android:layout_height="wrap_content"
  38. android:layout_below="@+id/my_customprogressbar3"
  39. android:layout_centerHorizontal="true"
  40. android:layout_marginTop="22dp"
  41. android:max="100"
  42. android:progress="40"
  43. android:secondaryProgress="60" />
  44.  
  45. <ProgressBar
  46. android:id="@+id/my_customprogressbar5"
  47. style="@style/mycustom_progressbar_hor2"
  48. android:layout_width="200dp"
  49. android:layout_height="wrap_content"
  50. android:layout_alignLeft="@+id/my_customprogressbar4"
  51. android:layout_below="@+id/my_customprogressbar4"
  52. android:layout_marginTop="26dp"
  53. android:max="100"
  54. android:progress="40"
  55. android:secondaryProgress="60" />
  56.  
  57. </RelativeLayout>

第一种圆形progressbar 只让一个图片旋转起来:

style的代码:

  1. <style name="mycustom_progressbar1">
  2. <item name="android:indeterminateDrawable">@drawable/progressbar_ver_image</item>
  3. <item name="android:minHeight">30dp</item>
  4. <item name="android:minWidth">30dp</item>
  5. <item name="android:maxHeight">60dp</item>
  6. <item name="android:maxWidth">60dp</item>
  7. </style>

progressbar_ver_image的代码:

  1. <?
  2.  
  3. xml version="1.0" encoding="utf-8"?>
  4. <!-- 定义一个旋转的动画 ,图片是我们自己定义的-->
  5. <rotate xmlns:android="http://schemas.android.com/apk/res/android"
  6. android:drawable="@drawable/resizeapi"
  7. android:fromDegrees="0"
  8. android:pivotX="50%"
  9. android:pivotY="50%"
  10. android:toDegrees="360" >
  11.  
  12. </rotate>

另外一种圆形progressbar 使用一个动画:

style:

  1. <style name="mycustom_progressbar2">
  2. <item name="android:indeterminateDrawable">@drawable/progressbar_ver_animation</item>
  3. <item name="android:minHeight">60dp</item>
  4. <item name="android:minWidth">60dp</item>
  5. <item name="android:maxHeight">100dp</item>
  6. <item name="android:maxWidth">100dp</item>
  7. </style>

progressbar_ver_animation的代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
  3.  
  4. <item
  5. android:drawable="@drawable/ok1"
  6. android:duration="250"/>
  7. <item
  8. android:drawable="@drawable/ok2"
  9. android:duration="250"/>
  10. <item
  11. android:drawable="@drawable/ok3"
  12. android:duration="250"/>
  13. <item
  14. android:drawable="@drawable/ok4"
  15. android:duration="250"/>
  16.  
  17. </animation-list>

第三种圆形progressbar 使用shape来构建drawable:

  1. <style name="mycustom_progressbar3">
  2. <item name="android:indeterminateDrawable">@drawable/progressbar_ver_shape</item>
  3. <item name="android:minHeight">60dp</item>
  4. <item name="android:minWidth">60dp</item>
  5. <item name="android:maxHeight">100dp</item>
  6. <item name="android:maxWidth">100dp</item>
  7. </style>

progressbar_ver_shape的代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- 定义一个旋转的动画 ,图片是我们自己定义的shape -->
  3. <rotate xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:fromDegrees="0"
  5. android:pivotX="50%"
  6. android:pivotY="50%"
  7. android:toDegrees="360" >
  8. <shape
  9. android:innerRadiusRatio="3"
  10. android:shape="ring"
  11. android:thicknessRatio="8"
  12. android:useLevel="false" >
  13. <gradient
  14. android:centerColor="#FFFFFF"
  15. android:centerY="0.50"
  16. android:endColor="#1E90FF"
  17. android:startColor="#000000"
  18. android:type="sweep"
  19. android:useLevel="false" />
  20. </shape>
  21.  
  22. </rotate>

第四种: 横向progressbar 复制粘贴系统的style,然后改动:

  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  4.  
  5. <item android:id="@android:id/background">
  6. <shape>
  7. <corners android:radius="5dip" />
  8. <gradient
  9. android:startColor="#ffff0000"
  10. android:centerColor="#ffff0000"
  11. android:centerY="0.75"
  12. android:endColor="#ffff0000"
  13. android:angle="270"
  14. />
  15. </shape>
  16. </item>
  17.  
  18. <item android:id="@android:id/secondaryProgress">
  19. <clip>
  20. <shape>
  21. <corners android:radius="5dip" />
  22. <gradient
  23. android:startColor="#800000ff"
  24. android:centerColor="#800000ff"
  25. android:centerY="0.75"
  26. android:endColor="#800000ff"
  27. android:angle="270"
  28. />
  29. </shape>
  30. </clip>
  31. </item>
  32.  
  33. <item android:id="@android:id/progress"
  34. >
  35. <clip >
  36.  
  37. <shape>
  38. <corners android:radius="5dip" />
  39. <gradient
  40. android:startColor="#ff00ff00"
  41. android:centerColor="#ff00ff00"
  42. android:centerY="0.75"
  43. android:endColor="#ff00ff00"
  44. android:angle="270"
  45. />
  46. </shape>
  47. </clip>
  48. </item>
  49.  
  50. </layer-list>

这样直接在progressbar中引用该style就能够满足需求了,当然我们也能够把progressbar background progress secondprogress都分别定义成一个drawable,然后使用:

background:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  2. <corners android:radius="5dip" />
  3. <gradient
  4. android:angle="270"
  5. android:centerColor="#ffff0000"
  6. android:centerY="0.75"
  7. android:endColor="#ffff0000"
  8. android:startColor="#ffff0000" />
  9. </shape>

progress:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  2.  
  3. <corners android:radius="5dip" />
  4.  
  5. <gradient
  6. android:angle="270"
  7. android:centerColor="#ff00ff00"
  8. android:centerY="0.75"
  9. android:endColor="#ff00ff00"
  10. android:startColor="#ff00ff00" />
  11.  
  12. </shape>

secondprogress:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  2.  
  3. <corners android:radius="5dip" />
  4.  
  5. <gradient
  6. android:angle="270"
  7. android:centerColor="#800000ff"
  8. android:centerY="0.75"
  9. android:endColor="#800000ff"
  10. android:startColor="#800000ff" />
  11.  
  12. </shape>

这个时候style中的代码就会清晰一点:

  1. <?
  2.  
  3. xml version="1.0" encoding="utf-8"?
  4.  
  5. >
  6. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  7.  
  8. <item
  9. android:id="@android:id/background"
  10. android:drawable="@drawable/progressbar_hor_bg">
  11. </item>
  12. <item android:id="@android:id/secondaryProgress">
  13. <clip android:drawable="@drawable/progressbar_hor_second_progress" >
  14. </clip>
  15. </item>
  16. <item android:id="@android:id/progress">
  17. <clip android:drawable="@drawable/progressbar_hor_progress" >
  18. </clip>
  19. </item>
  20.  
  21. <!-- progress 这个地方原作者写的是一个点9的图-->
  22. <!-- <item android:id="@android:id/progress">
  23. <clip>
  24. <nine-patch android:src="@drawable/progress_patch_galy" />
  25. </clip>
  26. </item> -->
  27. </layer-list>

嘿嘿..最后,做人要厚道:神一般男人的原博主博文连接http://blog.csdn.net/mad1989/article/details/38042875

对了,代码还是贴上来吧.总感觉在ide中直接看代码会更舒服一些:http://download.csdn.net/detail/u010399316/9000197

android 自己定义水平和圆形progressbar 仅仅定义一些style就能够的更多相关文章

  1. Android圆形图片--自己定义控件

    Android圆形图片控件效果图例如以下: 代码例如以下: RoundImageView.java package com.dxd.roundimageview; import android.con ...

  2. Android 圆形ProgressBar风格设置

    Android系统自带的ProgressBar风格不是很好,如果想自己设置风格的话,一般有几种方法.首先介绍一下第一种方法通过动画实现.在res的anim下创建动画资源loading.xml: < ...

  3. Android特效专辑(五)——自定义圆形头像和仿MIUI卸载动画—粒子爆炸

    Android特效专辑(五)--自定义圆形头像和仿MIUI卸载动画-粒子爆炸 好的,各位亲爱的朋友,今天讲的特效还是比较炫的,首先,我们会讲一个自定义圆形的imageView,接着,我们会来实现粒子爆 ...

  4. 自定义的圆形ProgressBar

        之前已经详细讲解过自定义控件的使用方式了.这里我单独把定以好的控件列出来. 之前定义的各式各样的ProgressBar http://www.cnblogs.com/tianzhijiexia ...

  5. 【Android自己定义View实战】之自己定义超简单SearchView搜索框

    [Android自己定义View实战]之自己定义超简单SearchView搜索框 这篇文章是对之前文章的翻新,至于为什么我要又一次改动这篇文章?原因例如以下 1.有人举报我抄袭,原文链接:http:/ ...

  6. 实现android手机来电拦截系统页面弹出自定义页面特效

    如何实现android手机来电拦截系统页面弹出自定义页面特效, 首先:    我们需要注册一个监听来电的广播PhoneStateReceiver 类:其次:    在onReceive里面我们获取an ...

  7. Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示

    Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android实现圆角矩形,圆形或者椭圆等图形,一般通过自定义ImageView来实现,首先获取到图片的Bitmap,然后通过 ...

  8. Android改变系统自带环形ProgressBar的大小

    MainActivity如下: package cc.testprogressbar; import android.os.Bundle; import android.app.Activity; / ...

  9. Android OpenGL ES(七)基本几何图形定义 .

    在前面Android OpenGL ES(六):创建实例应用OpenGLDemos程序框架 我们创建了示例程序的基本框架,并提供了一个“Hello World”示例,将屏幕显示为红色. 本例介绍Ope ...

随机推荐

  1. 深度学总结:skip-gram pytorch实现

    文章目录 skip-gram pytorch 朴素实现网络结构训练过程:使用nn.NLLLoss()batch的准备,为unsupervised,准备数据获取(center,contex)的pair: ...

  2. 洛谷——P1640 [SCOI2010]连续攻击游戏

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  3. 洛谷—— P1268 树的重量

    P1268 树的重量 构造类题目,看不出个所以然来... emmm,只好看题解: 只有两个点,那一条路径就是$ans$ 考虑三个点,那么$3$这个点相对于树上的路径(已经加入树上的边的距离) 为:$( ...

  4. SCOI2013 数数

    题目描述 题解: 很玄学的一道数位$dp$,看了很多篇题解才懂. 直接挂$l$的题解. 代码: #include<cstdio> #include<cstring> #incl ...

  5. 01-mysql中的数据类型

    mysql中的列数据类型:数值型.字符串类型.日期/时间类型3种 几种列类型描述使用了下述惯例:· M #表示最大显示宽度.最大有效显示宽度是255.· D #适用于浮点和定点类型,表示小数点后面的位 ...

  6. (11) openssl req(生成请求证书、私钥和自建CA)

    伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA. 由于openssl req命令选项较多,所以先各举几个例子,再集中给出openssl req的选项说明.若已熟悉opens ...

  7. POJ 3122 pie (二分法)

    Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have ...

  8. 项目如何发布到tomcat

    在eclipse上export 出WAR file 然后将文件放到tomcat中的webapps 上即可.

  9. python019 Python3 File(文件) 方法

    file 对象使用 open 函数来创建,下表列出了 file 对象常用的函数: 序号 方法及描述 1 file.close() 关闭文件.关闭后文件不能再进行读写操作. 2 file.flush() ...

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