3
我的目標是創建一個類似於餅圖的東西,但我無法得到非常正確的陰影。我希望陰影只在每個分段的外部曲線上,而不是通向中心的線條。除了編寫類似於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;