发布于 2017-08-26 11:16:08 | 185 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android自定义view实现太极效果实例代码的相关资料,需要的朋友可以参考下

Android自定义view实现太极效果实例代码

之前一直想要个加载的loading。却不知道用什么好,然后就想到了太极图标,最后效果是有了,不过感觉用来做loading简直丑到爆!!!

实现效果很简单,我们不要用什么贝塞尔曲线啥的,因为太极无非就是圆圆圆,只要画圆就ok了。来上代码:

因为有黑有白,所以定义2个画笔分别为黑和白。


private void inital() {
    whitePaint = new Paint();
    whitePaint.setAntiAlias(true);
    whitePaint.setColor(Color.WHITE);
    blackPaint = new Paint();
    blackPaint.setAntiAlias(true);
    blackPaint.setColor(Color.BLACK);
  }

最后来画3个圆就可以解决了:


 protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Point centerPoint = new Point(width / 2, height / 2);
    canvas.translate(centerPoint.x, centerPoint.y);
    canvas.rotate(angle);
    //绘制两个半圆
    int radius = Math.min(bitmapwidth, bitmapheight) / 2;
    RectF rect = new RectF(-radius, -radius, radius, radius);  //绘制区域
    canvas.drawArc(rect, 90, 180, true, blackPaint);      //绘制黑色半圆
    canvas.drawArc(rect, -90, 180, true, whitePaint);      //绘制白色半圆
    //绘制两个小圆
    int smallRadius = radius / 2;
    canvas.drawCircle(0, -smallRadius, smallRadius, blackPaint);
    canvas.drawCircle(0, smallRadius, smallRadius, whitePaint);
    //绘制鱼眼
    canvas.drawCircle(0, -smallRadius, smallRadius / 4, whitePaint);
    canvas.drawCircle(0, smallRadius, smallRadius / 4, blackPaint);
    if (load) {
      angle += 10;
      if (angle >= 360) {
        angle = 0;
      }
    }
    invalidate();
  }

是不是很简单,也就几行代码就解决了,一开始我还打算用贝塞尔曲线的(疯了!!)。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务