Rect.fromCircle({ Offset center, double radius })
center | 圆弧中心点(相对于原点的偏移量) |
radius | 圆弧半径(double) |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 100.0);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromLTRB(this.left, this.top, this.right, this.bottom)
left | 矩形最左边相对于原点(0,0)偏移量 |
top | 矩形最顶部相对于原点(0,0)偏移量 |
right | 矩形最右边相对于原点(0,0)偏移量 |
bottom | 矩形最底部相对于原点(0,0)偏移量 |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromLTRB(0.0, 0.0, size.width, size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromCenter({ Offset center, double width, double height })
center | 矩形中心相对于原点偏移量 |
width | 矩形宽度 |
height | 矩形高度 |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCenter(center: Offset(size.width/2,size.height/2),width:size.width/2,height:size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromLTWH(double left, double top, double width, double height)
left | 矩形最左边相对于原点偏移量 |
top | 矩形最顶部相对于原点偏移量 |
width | 矩形宽度 |
height | 矩形高度 |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromLTWH(0.0, 0.0, size.width/2, size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromPoints(Offset a, Offset b) : this.fromLTRB(
math.min(a.dx, b.dx),
math.min(a.dy, b.dy),
math.max(a.dx, b.dx),
math.max(a.dy, b.dy),
);
a | 相对于原点x方向上的偏移范围 |
b | 相对于原点y方向上的偏移范围 |
下面三种写法效果一样(主要是取x或y方向上偏移量的范围)
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=1.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromPoints(Offset(size.width, 0.0),Offset(0,size.height));
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=1.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromPoints(Offset(0.0, 0.0),Offset(size.width,size.height));
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=1.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromPoints(Offset(size.width, size.height),Offset(0.0,0.0));
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
useCenter=false(绘制扇形)
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 100.0);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromLTRB(0.0, 0.0, size.width, size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.lerp(在两个矩形之间进行线性插值)
源码:
static Rect lerp(Rect a, Rect b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return Rect.fromLTRB(b.left * t, b.top * t, b.right * t, b.bottom * t);
if (b == null) {
final double k = 1.0 - t;
return Rect.fromLTRB(a.left * k, a.top * k, a.right * k, a.bottom * k);
}
return Rect.fromLTRB(
lerpDouble(a.left, b.left, t),
lerpDouble(a.top, b.top, t),
lerpDouble(a.right, b.right, t),
lerpDouble(a.bottom, b.bottom, t),
);
}
double lerpDouble(num a, num b, double t) {
if (a == null && b == null)
return null;
a ??= 0.0;
b ??= 0.0;
return a + (b - a) * t;
}
a | 矩形 |
b | 矩形 |
t | 时间值(0.0~1.0之间) |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect a=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: size.width/3);
Rect b=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: size.width/2);
Rect rect=Rect.lerp(a, b, 1.0);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint);
rect=Rect.lerp(a, b, 0.2);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.blue);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect a=Rect.fromLTRB(80.0, 80.0, size.width-30.0, size.height-60.0);
Rect b=Rect.fromLTRB(50.0, 50.0, size.width-20.0, size.height-20.0);
Rect rect=Rect.lerp(a, b, 1.0);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint);
rect=Rect.lerp(a, b, 0.2);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.blue);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect a=Rect.fromLTRB(80.0, 80.0, size.width-80.0, size.height-80.0);
Rect b=Rect.fromLTRB(50.0, 50.0, size.width-50.0, size.height-50.0);
Rect rect=Rect.lerp(a, b, 1.0);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint);
rect=Rect.lerp(a, b, 0.7);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.blue);
rect=Rect.lerp(a, b, 0.5);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.green);
rect=Rect.lerp(a, b, 0.3);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.deepPurpleAccent);
rect=Rect.lerp(a, b, 0.1);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.cyanAccent);
rect=Rect.lerp(a, b, -0.2);
canvas.drawArc(rect, 0.0, 2*pi/4, true, paint…color=Colors.lightGreenAccent);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
画圆
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 100.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
画同心圆
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 100.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 80.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.blue);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 60.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.deepPurple);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 40.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.lightGreenAccent);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 20.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.grey);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 10.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.pinkAccent);
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 2.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.blueAccent);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
绘制渐变圆
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…invertColors=false;
Rect rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 100.0);
canvas.drawArc(rect, 0.0, 2*pi, false, paint…color=Colors.redAccent.withOpacity(0.2));
rect=Rect.fromCircle(center: Offset(size.width/2,size.height/2),radius: 80.0);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/215198b14ad4e115337d19d49b04846d.jpeg)
尾声
在我的博客上很多朋友都在给我留言,需要一些系统的面试高频题目。之前说过我的复习范围无非是个人技术博客还有整理的笔记,考虑到笔记是手写版不利于保存,所以打算重新整理并放到网上,时间原因这里先列出面试问题,题解详见:
展示学习笔记
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
[外链图片转存中…(img-bV0sKeeZ-1713312488260)]
[外链图片转存中…(img-NALwqDEN-1713312488262)]
[外链图片转存中…(img-XNqtCz66-1713312488263)]
[外链图片转存中…(img-9XFkl3Rh-1713312488263)]
[外链图片转存中…(img-YCNEl7YN-1713312488264)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/215198b14ad4e115337d19d49b04846d.jpeg)
尾声
在我的博客上很多朋友都在给我留言,需要一些系统的面试高频题目。之前说过我的复习范围无非是个人技术博客还有整理的笔记,考虑到笔记是手写版不利于保存,所以打算重新整理并放到网上,时间原因这里先列出面试问题,题解详见:
[外链图片转存中…(img-KONNPAzH-1713312488266)]
展示学习笔记
[外链图片转存中…(img-p6nnVsfi-1713312488267)]
[外链图片转存中…(img-dNKRWMl7-1713312488268)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!