作者:泥沙砖瓦浆木匠
网站http://blog.csdn.net/jeffli1993
个人签名:打算起手不凡写出鸿篇巨作的人,往往坚持不了完成第一章节。
交流QQ群:【编程之美 365234583】http://jq.qq.com/?_wv=1027&k=XVfBTo

一、前言

继续AndroidUI系列,UI其实是个前端活,美感是最终的boss阶段。泥瓦匠的美感也就给你们评论评论哈哈,我等UI写到一定地步。我想写下Android的一系列简单入门。为了巩固提升呗。哈哈。下面介入正题。
    有道是路漫漫其修远兮,吾将上下而求索。任何东西都不是一步登天,爱情啥都一样。钱也一样,没人愿意给你1亿,更何况也没愿意给你100的。为什么?没啥的,注意细节,一步一步来。让你值得那一亿就有了。但是要记住

“做人做事第一,技术第二”

二、正文

泥瓦匠是个爱扯的人。项目的进展也不错,前天友人通了个宵,或是今天降温了,想睡觉。晚上去锻炼下,应该就好了。哈哈~扯淡完毕。今天我们来实现下面这个界面:云通讯录项目之云端更新界面

先理理思路

  • 一个barTop层:一个ImgView或是Button,一个TextView,用styles.xml控制其的样式。
  • 核心中间一个圆形进度条的实现,自定义View。这次的核心讲解。
  • 底部ImgBottom的实现

三、实现圆形进度条

实现这个,首先我们得明白关于Canvas Paint的相关知识。这里我也就把涉及到的东西讲下。还是看效果说话吧。关于2D绘图的api都在android.graphics和android.graphics.drawable包里面。图形相关的有Point(点),RetcF(矩形)等,还有动画相关有AnimationDrawable、 BitmapDrawable和TransitionDrawable等。

本例中,其实我们用到的是很简单的两个操作。定义一个矩形(RetcF)然后再矩形区域,画弧线。一个弧线是对应的白色底部,另一个弧线是对应的进度。算好角度,然后就自然而然的可以了。话不多说,泥瓦匠就上代码了。(代码里面的详细注解,你也应该可以方便的看的懂。)

  1. package org.nsg.view;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.graphics.Color;
  6. import android.graphics.Paint;
  7. import android.graphics.Paint.Style;
  8. import android.graphics.RectF;
  9. import android.util.AttributeSet;
  10. import android.view.View;
  11. import android.view.animation.Animation;
  12. import android.view.animation.RotateAnimation;
  13.  
  14. public class CircleProgressBar extends View
  15. {
  16. private int maxProgress = 100;
  17. private int progress = 15;
  18. private int progressStrokeWidth = 16;
  19. private int marxArcStorkeWidth = 16;
  20. /* 画圆所在的距形区域 */
  21. RectF oval;
  22. Paint paint;
  23.  
  24. public CircleProgressBar(Context context, AttributeSet attrs)
  25. {
  26. super(context, attrs);
  27. oval = new RectF();
  28. paint = new Paint();
  29. }
  30.  
  31. @Override
  32. protected void onDraw(Canvas canvas)
  33. {
  34. super.onDraw(canvas);
  35. int width = this.getWidth();
  36. int height = this.getHeight();
  37.  
  38. width = (width > height) ? height : width;
  39. height = (width > height) ? height : width;
  40.  
  41. /* 设置画笔为抗锯齿 */
  42. paint.setAntiAlias(true);
  43. /* 设置画笔颜色 */
  44. paint.setColor(Color.WHITE);
  45. /* 白色背景 */
  46. canvas.drawColor(Color.TRANSPARENT);
  47. /* 线宽 */
  48. paint.setStrokeWidth(progressStrokeWidth);
  49. paint.setStyle(Style.STROKE);
  50.  
  51. /* 左上角x */
  52. oval.left = marxArcStorkeWidth / 2;
  53. /* 左上角y */
  54. oval.top = marxArcStorkeWidth / 2;
  55. /* 左下角x */
  56. oval.right = width - marxArcStorkeWidth / 2;
  57. /* 右下角y */
  58. oval.bottom = height - marxArcStorkeWidth / 2;
  59.  
  60. /* 绘制白色圆圈,即进度条背景 */
  61. canvas.drawArc(oval, -90, 360, false, paint);
  62. paint.setColor(Color.rgb(0x57, 0x87, 0xb6));
  63. paint.setStrokeWidth(marxArcStorkeWidth);
  64. /* 绘制进度圆弧,这里是蓝色 s*/
  65. canvas.drawArc(oval, -90, ((float) progress / maxProgress) * 360,false, paint);
  66.  
  67. /* 设置百分比文本 */
  68. paint.setStrokeWidth(1);
  69. String text = progress + "%";
  70. int textHeight = height / 4;
  71. paint.setTextSize(textHeight);
  72. int textWidth = (int) paint.measureText(text, 0, text.length());
  73. paint.setStyle(Style.FILL);
  74. canvas.drawText(text, width / 2 - textWidth / 2, height / 2 + textHeight / 2, paint);
  75.  
  76. }
  77.  
  78. public int getMaxProgress()
  79. {
  80. return maxProgress;
  81. }
  82.  
  83. public void setMaxProgress(int maxProgress)
  84. {
  85. this.maxProgress = maxProgress;
  86. }
  87.  
  88. /** 设置进度
  89. * @param progress 进度百分比
  90. * @param view 标识进度的节点视图
  91. */
  92. public void setProgress(int progress, View view)
  93. {
  94. this.progress = progress;
  95. view.setAnimation(pointRotationAnima(0,(int) (((float) 360 / maxProgress) * progress)));
  96. this.invalidate();
  97. }
  98.  
  99. /** 非UI线程调用 */
  100. public void setProgressNotInUiThread(int progress, View view)
  101. {
  102. this.progress = progress;
  103. view.setAnimation(pointRotationAnima(0,(int) (((float) 360 / maxProgress) * progress)));
  104. this.postInvalidate();
  105. }
  106.  
  107. /** 进度标注点的动画
  108. * @param fromDegrees
  109. * @param toDegrees
  110. */
  111. private Animation pointRotationAnima(float fromDegrees, float toDegrees)
  112. {
  113. /* 进度点起始位置(图片偏移约54度) */
  114. int initDegress = 300;
  115. RotateAnimation animation =
  116. new RotateAnimation(fromDegrees,
  117. initDegress + toDegrees,
  118. Animation.RELATIVE_TO_SELF,
  119. 0.5f,
  120. Animation.RELATIVE_TO_SELF,
  121. 0.5f);
  122. /* 设置动画执行时间 */
  123. animation.setDuration(1);
  124. /* 设置重复执行次数 */
  125. animation.setRepeatCount(1);
  126. /* 设置动画结束后是否停留在结束位置 */
  127. animation.setFillAfter(true);
  128. return animation;
  129. }
  130.  
  131. }
  1.  
  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=".MainActivity" >
  6.  
  7. <RelativeLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="46dp"
  10. android:background="@drawable/bg_black">
  11. <ImageView
  12. android:id="@+id/img_user_list_back"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_alignParentLeft="true"
  16. android:paddingLeft="24dp"
  17. android:paddingTop="10dp"
  18. android:paddingBottom="10dp"
  19. android:clickable="true"
  20. android:focusable="true"
  21. android:scaleType="fitXY"
  22. android:src="@drawable/btn_return"/>
  23. <TextView
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. style="@style/txt_topbar"
  27. android:text="云端更新"/>
  28. </RelativeLayout>
  29.  
  30. <org.nsg.main.CircleProgressBar
  31. android:id="@+id/sync_progress"
  32. android:layout_width="200dp"
  33. android:layout_height="200dp"
  34. android:layout_marginBottom="210dp"
  35. android:layout_alignBottom="@+id/lay_bottom"
  36. android:layout_centerHorizontal="true"
  37. />
  38.  
  39. <LinearLayout
  40. android:layout_width="match_parent"
  41. android:layout_height="50dp"
  42. android:layout_marginBottom="140dp"
  43. android:layout_alignBottom="@+id/lay_bottom">
  44.  
  45. <TextView
  46. android:id="@+id/syncText"
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:textColor="@color/red"
  50. android:paddingLeft="50dp"
  51. android:textSize="15sp"
  52. android:text="温馨提醒:"/>
  53.  
  54. <TextView
  55. android:id="@+id/syncText"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:textColor="@color/black"
  59. android:textSize="15sp"
  60. android:text="在Wifi下,更新更有效果"/>
  61.  
  62. </LinearLayout>
  63.  
  64. <Button
  65. android:id="@+id/syncButton"
  66. android:layout_width="fill_parent"
  67. android:layout_height="wrap_content"
  68. android:layout_marginLeft="20dp"
  69. android:layout_marginRight="20dp"
  70. android:layout_marginBottom="90dp"
  71. android:layout_alignBottom="@+id/lay_bottom"
  72. android:textColor="@color/white"
  73. android:textSize="22sp"
  74. android:background="@drawable/user_detail_call_bg"
  75. android:text="更新" />
  76.  
  77. <LinearLayout
  78. android:id="@+id/lay_bottom"
  79. android:layout_width="fill_parent"
  80. android:layout_height="wrap_content"
  81. android:orientation="horizontal"
  82. android:layout_alignParentBottom="true">
  83. <ImageView
  84. android:layout_width="match_parent"
  85. android:layout_height="wrap_content"
  86. android:src="@drawable/libe_footer" />
  87. </LinearLayout>
  88.  
  89. </RelativeLayout>

定义好这个View之后,我们就把最难的东西搞定了。代码里面,最后用动画的形式展现给大家,百分比会根据你设计的百分比进行变化。泥瓦匠和大家一样,都想急切的看到效果图,只要大家如下简单的操作就好了。打开设计的xml文件详细的xml设计我也方便大家贴出来了:其他设计都是简单的,我这边也不展开讲了。

四、总结

本章关于云通讯录的界面我会慢慢分享给大家。项目也放在下面的链接供大家下载学习。这期就到这里,泥瓦匠也要休息了。关于代码在下面的链接:http://files.cnblogs.com/Alandre/AndroidUI04.rar

如以上文章或链接对你有帮助的话,别忘了在文章按钮或到页面右下角点击 “赞一个” 按钮哦。你也可以点击页面右边“分享”悬浮按钮哦,让更多的人阅读这篇文章

Android UI(四)云通讯录项目之云端更新进度条实现的更多相关文章

  1. Android UI系列-----时间、日期、Toasts和进度条Dialog

    您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...

  2. 【转】Android UI系列-----时间、日期、Toasts和进度条Dialog

    原文网址:http://www.cnblogs.com/xiaoluo501395377/p/3421727.html 您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注 ...

  3. Android UI(五)云通讯录项目之联系人列表,带侧滑选择,带搜索框

    作者:泥沙砖瓦浆木匠网站:http://blog.csdn.net/jeffli1993个人签名:打算起手不凡写出鸿篇巨作的人,往往坚持不了完成第一章节.交流QQ群:[编程之美 365234583]h ...

  4. android AsyncTask异步下载并更新进度条

    AsyncTask异步下载并更新进度条    //如果不是很明白请看上篇文章的异步下载 AsyncTask<String, Integer, String> 第一个参数:String 传入 ...

  5. Android 自定义View—清爽小巧灵活的多节点进度条

    前言 最近项目有一个节点进度条的小需求,完成后,想分享出来希望可以帮到有需要的同学. 真机效果图 自定义View完整代码 开箱即用~,注释已经炒鸡详细了 /** * @description: 节点进 ...

  6. Android开发 ---基本UI组件4:拖动事件、评分进度条、圆圈式进度条、进度条控制

    Android开发 ---基本UI组件4 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding=" ...

  7. Android -- 真正的 高仿微信 打开网页的进度条效果

    (本博客为原创,http://www.cnblogs.com/linguanh/) 目录: 一,为什么说是真正的高仿? 二,为什么要搞缓慢效果? 三,我的实现思路 四,代码,内含注释 五,使用方法与截 ...

  8. (四十二)c#Winform自定义控件-进度条扩展

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  9. android一个上传图片的样例,包含怎样终止上传过程,假设在上传的时候更新进度条(一)

    先上效果图: Layout为: <? xml version="1.0" encoding="utf-8"?> <LinearLayout x ...

随机推荐

  1. MongoDB + Express 环境搭建记

    最近项目需要使用 MongoDB,所以不得不搭建 MongoDB 环境,此文记录搭建过程及使用过程中需要了解的问题. Linux + Windows 混合搭建调试 MongoDB 记录 版本介绍 : ...

  2. 解决sqlserver数据库表空间不自动释放问题

    在项目中遇到了sql server数据库经过频繁地删减数据后,查询变慢的问题. 我把数据导到另一个库中,发现查询就很快. 查了下原因,根本原因是删除数据并不释放表空间,日志文件太过巨大的原因. 网上查 ...

  3. C#在SharePoint文档库下动态新增文件夹

    /// <summary> /// 在创建SP文库库下动态新增文件夹 /// </summary> /// <param name="spList"& ...

  4. spring BeanPostProcessor

    BeanPostProcessor spring使用BeanPostProcessor接口来处理生命周期的回调 BeanPostProcessor接口定义的两个方法,分别在bean的(实例化配置和初始 ...

  5. XML生成XAMl扩展

    所有的WPF控件列为枚举 代码如: 1 public enum ControlType 2 { 3 Window_Resources, 4 Page_Resources, 5 Grid, 6 Stac ...

  6. IDEA安装插件提示was not installed: Cannot download解决办法

    打开settings->system settings->updata,把下面的Use secure Connetion去掉

  7. vue.js 系列教程

    Vuejs——(1)入门(单向绑定.双向绑定.列表渲染.响应函数) Vuejs——(2)Vue生命周期,数据,手动挂载,指令,过滤器 Vuejs——(3)计算属性,样式和类绑定 Vuejs——(4)v ...

  8. Maven2-坐标

    什么是Maven坐标? 在生活中,每个城市,地点,都有自己独一无二的坐标,这样快递小哥才能将快递送到我们手上.类似于现实生活,Maven的世界也有很多城市,那就是数量巨大的构件,也就是我们平时用的ja ...

  9. Linux tgtadm: Setup iSCSI Target ( SAN )

    Linux target framework (tgt) aims to simplify various SCSI target driver (iSCSI, Fibre Channel, SRP, ...

  10. Windows 10 IoT Core 17133 for Insider 版本更新

    今天,微软发布了Windows 10 IoT Core 17133 for Insider 版本更新,本次更新只修正了一些Bug,没有发布新的特性.用户可以登录Windows Device Porta ...