gpt4 book ai didi

android - 在具有浮雕效果的android中绘制圆边弧

转载 作者:IT老高 更新时间:2023-10-28 22:16:36 26 4
gpt4 key购买 nike

我正在尝试开发一个自定义组件,即弧形 slider ,我完成了弧形和拇指,但无法弄清楚如何绘制圆边弧以及其中的浮雕效果。目前 slider 看起来像这样

enter image description here

画圆弧的代码是

private void drawSlider(Canvas canvas) {
float sweepDegrees = (value * arcWidthInAngle)
/ (maximumValue - minimumValue);

// the grey empty part of the circle
drawArc(canvas, startAngle, arcWidthInAngle, mTrackColor);
// the colored "filled" part of the circle
drawArc(canvas, startAngle, sweepDegrees, mFillColor);

// the thumb to drag.
int radius = ((diameter/2) - (mArcThickness/2));
Point thumbPoint = calculatePointOnArc(centerX, centerY, radius, startAngle + sweepDegrees);

thumbPoint.x = thumbPoint.x - (mThumbDiameter/2);
thumbPoint.y = thumbPoint.y - (mThumbDiameter/2);

Bitmap thumbBitmap = BitmapFactory.decodeResource(
mContext.getResources(), R.drawable.circle25);

thumbBitmap = getResizedBitmap(thumbBitmap, mThumbDiameter, mThumbDiameter);
canvas.drawBitmap(thumbBitmap, thumbPoint.x, thumbPoint.y,
null);

}

private void drawArc(Canvas canvas, float startAngle, float sweepDegrees,
Paint paint) {
if (sweepDegrees <= 0 || sweepDegrees > arcWidthInAngle) {
return;
}
path.reset();
path.arcTo(outerCircle, startAngle, sweepDegrees);
path.arcTo(innerCircle, startAngle + sweepDegrees, -sweepDegrees);
// innerCircle.
path.close();
canvas.drawPath(path, paint);
}

我的目标是这样的弧

enter image description here

最佳答案

对于圆形边缘,您可以使用 Paint.setStrokeCap() 方法。此外,默认的油漆帽是 BUTT。您应该改用 Paint.Cap.ROUND 帽。

例如:

Paint mFillColor = new Paint();
mFillColor.setStrokeCap(Paint.Cap.ROUND)

关于android - 在具有浮雕效果的android中绘制圆边弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10784208/

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