Android自定义之圆形进度条
2016-04-18 15:29
387 查看
先来看看效果图,有图才有真相:
Maven
eclipse
请下载https://github.com/HpWens/ProgressDemo,依赖
完成上面的依赖后,在布局文件中声明控件:
Activity文件中:
这样一个简单的进度条就出现在我们的眼前了:
静止的进度条:
当然你可能有更好的建议和方案,可以给我留言。学习很多时候就是在积累经验。源码地址请关注https://github.com/HpWens/ProgressDemo
Usage
Android Studio 使用Gradle构建dependencies { compile 'com.github.ws.circleprogress:circleprogress:2.1.5' }
Maven
<dependency> <groupId>com.github.ws.circleprogress</groupId> <artifactId>circleprogress</artifactId> <version>2.1.5</version> <type>pom</type> </dependency>
eclipse
请下载https://github.com/HpWens/ProgressDemo,依赖
circleprogress包
完成上面的依赖后,在布局文件中声明控件:
<com.example.circleprogress.app.BarCircleProgress xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bcp" app:backgroundColor="#0ff000" android:layout_width="200dp" android:layout_height="200dp" />
Activity文件中:
bcp= (BarCircleProgress) findViewById(R.id.bcp);
这样一个简单的进度条就出现在我们的眼前了:
静止的进度条:
<com.example.circleprogress.app.BarCircleProgress android:id="@+id/bcp" android:layout_width="200dp" android:layout_height="200dp" app:backgroundColor="#0ff000" app:currentProgress="20" app:isMove="false" />
Attribute
进度条的基础属性:/** * 设备背景颜色 * * @param color */ public void setBackgroundColor(int color) { backgroundPaint.setColor(color); } /** * 设置背景风格 * * @param style * @param width */ public void setBackgroundStyle(Paint.Style style, float width) { backgroundPaint.setStyle(style); if (style == Paint.Style.STROKE) { backgroundPaint.setStrokeWidth(DensityUtil.dip2px(ctx, width)); } } /** * 设置背景空心 宽度 * * @param width */ public void setBackgroundStrokeWidth(float width) { backgroundPaint.setStyle(Paint.Style.STROKE); backgroundPaint.setStrokeWidth(DensityUtil.dip2px(ctx, width)); } /** * 设置背景 的笔触类型 * * @param cap */ public void setBackgroundStrokeCap(Paint.Cap cap) { backgroundPaint.setStrokeCap(cap); } /** * 设置进度条 的笔触类型 * * @param cap */ public void setProgressStrokeCap(Paint.Cap cap) { progressPaint.setStrokeCap(cap); } /** * 设置进度条颜色 * * @param color */ public void setProgressColor(int color) { progressPaint.setColor(color); } /** * 设置进度条风格 * * @param style * @param width */ public void setProgressStyle(Paint.Style style, float width) { progressPaint.setStyle(style); if (style == Paint.Style.STROKE) { progressPaint.setStrokeWidth(DensityUtil.dip2px(ctx, width)); } } /** * 设置文字颜色 * * @param color */ public void setTextColor(int color) { textPaint.setColor(color); } /** * 设置文字大小 * * @param size */ public void setTextSize(float size) { textPaint.setTextSize(DensityUtil.dip2px(ctx, size)); } /** * 设置最大进度 * * @param maxProgress */ public void setMaxProgress(int maxProgress) { this.maxProgress = maxProgress; } /** * 设置当前进度 * * @param currentProgress */ public void setCurrentProgress(int currentProgress) { this.currentProgress = currentProgress; } /** * 设置开始角度 * * @param angle */ public void setStartAngle(float angle) { this.startAngle = angle; } /** * 是否是静止界面 还是动态界面 * * @param isMove */ public void setIsMove(boolean isMove) { this.isMove = isMove; } /** * 设置文本单位符号 */ public void setTextUnit(Unit mUnit) { switch (mUnit) { case TEMP: this.textUnit = TEMP_UNIT; break; case PERCENT: this.textUnit = PERCENT_UNIT; break; } } /** * @param size 0.0f~1.0f */ public void setCircleSize(float size) { this.circleSize = size; }
当然你可能有更好的建议和方案,可以给我留言。学习很多时候就是在积累经验。源码地址请关注https://github.com/HpWens/ProgressDemo
相关文章推荐
- JNCryptor在Android上的性能其差无比,而在iOS上RNCryptor则其强无比 何解?
- Android 使用SimpleCursorAdapter为listview的item添加按钮
- AndroidManifest:VersionCode和VersionName
- Android 开源框架ActionBarSherlock 和 ViewPager 仿网易新闻客户端
- android:paddingRight="5dp"在xml文件中报错
- mac下android环境搭建笔记(android studio)
- Android Bitmap
- Android中统计图的使用
- Android知识梳理之Sqlite数据库的使用和优化
- Android仿联系人列表分组悬浮列表,PinnedHeaderListView源码解析
- Android中为图标加上数字--用于未读短信数提醒等
- Android突击:什么情况会导致Force Close ?如何避免?能否捕获导致其的异常?
- 52.关于Android Studio项目的Gradle构建
- Android SurfaceView使用详解
- Android基础--EditText输入框限制小数的位数解决方法
- Android的视频通话的Java代码 anychat
- android Fragment中遇到的问题
- 解决android:layout_marginBottom在RelativeLayout中无效的bug
- Android ViewDragHelper:控制子View能否拖曳及水平方向的拖曳边界(2)
- Android Studio---定制属于自己的注解模板