转圈进度条
来源:互联网 发布:淘宝流量闭环什么意思 编辑:程序博客网 时间:2024/05/16 01:12
效果图
public class RCircleView extends View { private Paint paint; private int color = 0xff04ade5; private int degree;//让画布旋转一个角度再画图,就像圈圈一直在转一样 public RCircleView(Context context) { this(context, null); } public RCircleView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public RCircleView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(150); degree += 30; if (degree == 360) { degree = 0; } postInvalidate(); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int w = 0, h = 0; if (widthMode == MeasureSpec.EXACTLY) { w = widthSize; } else { w = dp2px(80); } if (heightMode == MeasureSpec.EXACTLY) { h = heightSize; } else { h = dp2px(80); } setMeasuredDimension(w, h); } private int dp2px(int dp) { float density = getContext().getResources().getDisplayMetrics().density; return (int) (dp * density + 0.5); } @Override protected void onDraw(Canvas canvas) { canvas.save(); //画布默认是在左上角旋转,移动位置到控件中间再旋转,旋转完成后再移动回去 canvas.translate(getWidth() / 2, getHeight() / 2); canvas.rotate(degree); canvas.translate(-getWidth() / 2, -getHeight() / 2); onDrawCircle(canvas); canvas.restore(); } private void onDrawCircle(Canvas canvas) { float cx = getWidth() / 2, cy = getHeight() / 2; float r = Math.min(getWidth(), getHeight()) * 5.0f / 12;//要画的小圆圈距中心的距离 for (int i = 1; i <= 12; i++) { float angle = (float) (i * Math.PI / 6); //xy是小圆圈的圆点坐标 float x = (float) (cx + r * Math.sin(angle)); float y = (float) (cy - r * Math.cos(angle)); float rr = r / 5;//最大小圆点的半径 rr *= (10.0f / 33 + i * 1.0f / 33);//第i个小圆点的半径 int alpha = (int) (i * 255.f / 12);//第i个圆点的透明度 paint.setColor((alpha << 24) | (color & 0x00ffffff)); canvas.drawCircle(x, y, rr, paint);//画圆点 } }}
要说的只有圆点的透明度,color&0x00ffffff得到颜色的agb不带透明度,alpha后面24位表示rgb,左移24位得到0xff000000这样的只带透明度的。和色值|之后就得到完整色值。
0 0
- 转圈进度条
- iOS转圈进度条
- android 水平和转圈的进度条
- bee中下载网络资源时,加载转圈的进度条
- 转圈圈
- 转圈游戏
- 转圈游戏
- 转圈游戏
- 转圈游戏
- 转圈游戏
- 转圈算法
- 转圈打印矩阵或者生成转圈矩阵
- 生活就是转圈...
- 今天转圈问题
- Android ProgressDialog 转圈圈
- 转圈数 java
- 转圈数数淘汰
- wikioi 3285 转圈游戏
- R语言源码安装插件包
- linux 的文件操作命令整理
- El、JSTL
- linux中 epoll
- 怎样在Android中使用Loaders
- 转圈进度条
- 文章标题
- spring declarative transaction management
- 深入理解Java:类加载机制及反射
- 转 Linux环境下USB的原理、驱动和配置--本文由CSDN 特别约稿,作者为北京中科红旗软件技术有限公司 嵌入式工程师 梁国军
- instruments 静态分析常见问题
- LightOJ 1149 Factors and Multiples 最大匹配--匈牙利算法
- vi常用命令
- UML建模详解(4)—类图与对象图的对比分析