我的目标是创建类似于饼图的东西,但我无法完全正确地绘制阴影。我希望阴影位于每个段的外侧曲线上,而不是通往中心的线。除了编写类似于的自定义函数之外,还有其他方法可以实现paint.setShadowLayer()
吗?
这是我到目前为止所拥有的:
float mStart = 0;
RectF mOvals = new RectF(mWidth / 15 + mGraphParams.leftMargin, mHeight / 15 + mGraphParams.topMargin,
mWidth - mWidth / 15 - mGraphParams.rightMargin, mHeight - mHeight / 15 - mGraphParams.bottomMargin);
float max = 0;
for (int i = 0; i < data.size(); i++) {
max = max + data.get(i);
}
for (int i = 0; i < data.size(); i++) {
if (shadow) {
paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, this.pieColors.get(i));
}
float mSweep = (float) 360 * ((float) data.get(i) / max);
paint.setStyle(Style.FILL_AND_STROKE);
paint.setColor(this.pieColors.get(i));
canvas.drawArc(mOvals, mStart, mSweep, true, paint);
mStart = mStart + mSweep;