作者:泥沙砖瓦浆木匠
网站: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)然后再矩形区域,画弧线。一个弧线是对应的白色底部,另一个弧线是对应的进度。算好角度,然后就自然而然的可以了。话不多说,泥瓦匠就上代码了。(代码里面的详细注解,你也应该可以方便的看的懂。)

package org.nsg.view;import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;public class CircleProgressBar extends View
{private int maxProgress = 100;private int progress = 15;private int progressStrokeWidth = 16;private int marxArcStorkeWidth = 16;/* 画圆所在的距形区域 */RectF oval;Paint paint;public CircleProgressBar(Context context, AttributeSet attrs) {super(context, attrs);oval = new RectF();paint = new Paint();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);int width = this.getWidth();int height = this.getHeight();width  = (width > height) ? height : width;height = (width > height) ? height : width;/* 设置画笔为抗锯齿 */paint.setAntiAlias(true);/* 设置画笔颜色 */paint.setColor(Color.WHITE); /* 白色背景 */canvas.drawColor(Color.TRANSPARENT);/* 线宽 */paint.setStrokeWidth(progressStrokeWidth);paint.setStyle(Style.STROKE);/* 左上角x */oval.left = marxArcStorkeWidth / 2;/* 左上角y */oval.top  = marxArcStorkeWidth / 2; /* 左下角x */oval.right  = width  - marxArcStorkeWidth / 2;/* 右下角y */oval.bottom = height - marxArcStorkeWidth / 2;/* 绘制白色圆圈,即进度条背景 */canvas.drawArc(oval, -90, 360, false, paint);paint.setColor(Color.rgb(0x57, 0x87, 0xb6));paint.setStrokeWidth(marxArcStorkeWidth);/* 绘制进度圆弧,这里是蓝色 s*/canvas.drawArc(oval, -90, ((float) progress / maxProgress) * 360,false, paint);/* 设置百分比文本 */paint.setStrokeWidth(1);String text = progress + "%";int textHeight = height / 4;paint.setTextSize(textHeight);int textWidth = (int) paint.measureText(text, 0, text.length());paint.setStyle(Style.FILL);canvas.drawText(text, width / 2 - textWidth / 2, height / 2 + textHeight / 2, paint);}public int getMaxProgress(){return maxProgress;}public void setMaxProgress(int maxProgress){this.maxProgress = maxProgress;}/** 设置进度* @param progress 进度百分比* @param view  标识进度的节点视图*/public void setProgress(int progress, View view) {this.progress = progress;view.setAnimation(pointRotationAnima(0,(int) (((float) 360 / maxProgress) * progress)));this.invalidate();}/** 非UI线程调用 */public void setProgressNotInUiThread(int progress, View view) {this.progress = progress;view.setAnimation(pointRotationAnima(0,(int) (((float) 360 / maxProgress) * progress)));this.postInvalidate();}/** 进度标注点的动画* @param fromDegrees* @param toDegrees*/private Animation pointRotationAnima(float fromDegrees, float toDegrees) {/* 进度点起始位置(图片偏移约54度) */int initDegress = 300;RotateAnimation animation = new RotateAnimation(fromDegrees,initDegress + toDegrees,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);/* 设置动画执行时间 */animation.setDuration(1);/* 设置重复执行次数 */animation.setRepeatCount(1);/* 设置动画结束后是否停留在结束位置 */animation.setFillAfter(true);return animation;}}
 
<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" ><RelativeLayout android:layout_width="match_parent"android:layout_height="46dp"android:background="@drawable/bg_black"><ImageView android:id="@+id/img_user_list_back"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:paddingLeft="24dp"android:paddingTop="10dp"android:paddingBottom="10dp"android:clickable="true"android:focusable="true"android:scaleType="fitXY"android:src="@drawable/btn_return"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"style="@style/txt_topbar"android:text="云端更新"/></RelativeLayout><org.nsg.main.CircleProgressBarandroid:id="@+id/sync_progress"android:layout_width="200dp"android:layout_height="200dp"android:layout_marginBottom="210dp"android:layout_alignBottom="@+id/lay_bottom"android:layout_centerHorizontal="true"/><LinearLayout android:layout_width="match_parent"android:layout_height="50dp"android:layout_marginBottom="140dp"android:layout_alignBottom="@+id/lay_bottom"><TextViewandroid:id="@+id/syncText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/red"android:paddingLeft="50dp"android:textSize="15sp"android:text="温馨提醒:"/><TextViewandroid:id="@+id/syncText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/black"android:textSize="15sp"android:text="在Wifi下,更新更有效果"/></LinearLayout><Buttonandroid:id="@+id/syncButton"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:layout_marginBottom="90dp"android:layout_alignBottom="@+id/lay_bottom"android:textColor="@color/white"android:textSize="22sp"android:background="@drawable/user_detail_call_bg"android:text="更新" /><LinearLayout android:id="@+id/lay_bottom"android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true"> <ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:src="@drawable/libe_footer" /></LinearLayout></RelativeLayout>

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

四、总结

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

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

Android UI(四)云通讯录项目之云端更新进度条实现相关推荐

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

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

  2. Android 自定义View,自定义属性--自定义圆形进度条(整理)

    很多的时候,系统自带的View满足不了我们的功能需求,那么我们就需要自定义View来满足我们的需求 自定义View时要先继承View,添加类的构造方法,重写父类View的一些方法,例如onDraw,为 ...

  3. android插件数字,Android自定义控件实现带文本与数字的圆形进度条

    本文实例为大家分享了Android实现圆形进度条的具体代码,供大家参考,具体内容如下 实现的效果图如下所示: 第一步:绘制下方有缺口的空心圆,称为外围大弧吧 anvas.clipRect(0, 0, ...

  4. Android中通过SeekBar手动控制ProgressBar与模拟下载自动更新进度条

    场景 进度条的常用场景: 通过SeekBar拖动进而更新ProgressBar进度条,比如调整音量效果等. 模拟下载实现自动更新进度条. 注: 博客: https://blog.csdn.net/ba ...

  5. 打开Unity项目,加载进度条一直显示busy不消失

    打开Unity项目,加载进度条一直显示busy不消失 解决办法:我的项目路径存在中文,改成全英文路径再打开一下就好了.

  6. 阿里云视频上传视频获取进度条问题(使用session方案,获取进度一直为0的解决方案)补充:前后端分离项目中获取进度解决方案

    1.场景描述: 之前用阿里云上传视频,前端反应上传视频经常出现获取视频url失败问题.但是接口我测过很多遍都是没有问题的.后台这边提供了一个视频上传的接口返回一个videoId,还提供了一个根据vid ...

  7. Android自定义View之画圆环(进阶篇:圆形进度条)

    前言: 如果你想读懂或者更好的理解本篇文章关于自定义圆环或圆弧的内容.请你务必提前阅读下Android自定义View之画圆环(手把手教你如何一步步画圆环).在这篇文章中,详细描述了最基本的自定义圆环的 ...

  8. vue+天翼云OOS文件存储+上传进度条

    在使用天翼云文件存储时,发现官方文档里写的不太多.网上相关的资料也很少,关于上传进度条的更是几乎没有.跟官方的技术人员对接后,整理前端使用教程如下: 在public文件夹下放置天翼云OOS的js文件, ...

  9. [Android]webview直接加载网页允许JS,进度条,当前应用内跳转

    webview,用于在应用里面直接加载网页 本代码参考了: 官方的webview实例介绍:https://developer.android.com/guide/tutorials/views/hel ...

最新文章

  1. [Asp.net 5] Options-配置文件(2)
  2. win10 右键 命令行
  3. Proguard混淆代码(1)
  4. qq第三方登录注册php,QQ第三方登录PHP
  5. centos7 yum下载路径
  6. c++中为什么父类名可以直接调用自己的非静态函数测试例子!(父类名::非静态函数)
  7. 按照时间,每天分区;按照数字,200000一个分区
  8. 【lucene】Lucene Tika 操作各种文件
  9. Python之list每个元素小数点精度控制
  10. hadoop 文件介绍
  11. MIT要和世界各地研究机构合作,让机器能像婴儿一样学习
  12. Heartbeat实现web服务器高可用
  13. 常用js框架,js库
  14. 解析kml文件,提取经纬度信息存入csv
  15. 视频质量评价 VMAF,为何让人又喜又忧?
  16. 智能交通大数据体系实践
  17. Google Web Accelerator
  18. 2.2.1 hadoop体系之离线计算-mapreduce分布式计算-mapreduce架构概念
  19. Codeforces Round #789 (Div. 1) B. Tokitsukaze and Meeting
  20. 1024px是个好模版

热门文章

  1. 黑色全屏个人主页bootstrap4模板
  2. SignalR介绍与Asp.net
  3. C# 实现软件自动更新升级程序
  4. ORM组件XCode(十八般武艺)
  5. 自己动手架设linux下Web服务器(图)5
  6. Linux: chmod 和 chown用法小结
  7. Shopify 入门 (英文)
  8. vagrant 报unknown filesystem type 'vboxsf' 解决方案
  9. 【转载】Python线程、进程和协程详解
  10. Windows10系统下,彻底删除卸载MySQL