gpt4 book ai didi

Android绘制Canvas贝塞尔曲线及进度

转载 作者:行者123 更新时间:2023-11-30 01:51:55 26 4
gpt4 key购买 nike

我正在尝试在自定义 View 中绘制类似的东西,它是一个带有复杂波浪的进度条 enter image description here

进度是相同的贝塞尔曲线,但我只显示了一部分取决于百分比。 this would be the final result

实际上,感谢@Blackbelt,我设法绘制了贝塞尔曲线并填充了背景形状,

        Paint paintBezzier = new Paint() {
{
setStyle(Style.FILL_AND_STROKE);
setStrokeCap(Paint.Cap.ROUND);
setStrokeWidth(10.0f);
setAntiAlias(true);
}
};

Paint paintBezzierProgressBase = new Paint() {
{
setStyle(Style.STROKE);
setStrokeCap(Paint.Cap.ROUND);
setStrokeWidth(10.0f);
setAntiAlias(true);
}
};


int xControl1 = 0;
int yControl1 = 0;

int xControl2 = 0;
int yControl2 = 0;


int x1 = 0;
int y1 = contentHeight/2;

int x2 = contentWidth;
int y2 = contentHeight/2;

xControl1 = contentWidth/2;
yControl1 = 0 - 40;

xControl2 = contentWidth/2;
yControl2 = contentHeight+40;


Path backgroundPath = new Path();
paintBezzier.setColor(Color.parseColor("#ffffff"));
paintBezzier.setStrokeWidth(5);
backgroundPath.moveTo(x1, y1);
backgroundPath.cubicTo(xControl1, yControl1, xControl2, yControl2, x2, y2);
backgroundPath.lineTo(x2, y2);
backgroundPath.lineTo(contentWidth, contentHeight);
backgroundPath.lineTo(x1, contentHeight);
backgroundPath.lineTo(x1, y1);
backgroundPath.close();

//TODO calculate progress

Path pathProgress = new Path();
paintBezzierProgressBase.setColor(Color.parseColor("#F1AD3D"));
paintBezzierProgressBase.setStrokeWidth(7);
pathProgress.moveTo(x1, y1);
pathProgress.cubicTo(xControl1, yControl1, xControl2, yControl2, x2, y2);


canvas.drawPath(backgroundPath, paintBezzier);
canvas.drawPath(path, paintBezzierProgressBase);

知道如何计算百分比并仅显示曲线的一部分吗?这是图像目标。

提前致谢对不起我的英语

最佳答案

尝试使用 FILL_AND_STROKE 作为 paintBezzier 的样式,而不是 STROKE。或者您可能还想关闭要绘制的周围区域,然后使用其中一种路径填充样式

关于Android绘制Canvas贝塞尔曲线及进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32912654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com