怎么在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();
}
关于怎么在Android中利用view实现一个太极效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。