栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

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

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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();
  }

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/158775.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号