目前我使用GITHUB的MPAndroidChart並繪製了餅圖來顯示兩行文字,每行都有不同的顏色和不同的字體大小,我檢查了源代碼和文本中心是一個字符串對象,並嘗試使用:MPAndroidChart PieChart如何更改中心文字以顯示不同的顏色和字體大小
PAINT paint = pie_chart.getPaint(Chart.PAINT_CENTER_TEXT);
不過貌似不行的,會有人有經驗做指導我。
目前我使用GITHUB的MPAndroidChart並繪製了餅圖來顯示兩行文字,每行都有不同的顏色和不同的字體大小,我檢查了源代碼和文本中心是一個字符串對象,並嘗試使用:MPAndroidChart PieChart如何更改中心文字以顯示不同的顏色和字體大小
PAINT paint = pie_chart.getPaint(Chart.PAINT_CENTER_TEXT);
不過貌似不行的,會有人有經驗做指導我。
研究源代碼後,我改變PieChartRenderer.java改變 mCenterTextPaint.setColor(Color.parseColor("#333333")); mCenterTextPaint.setTextSize(Utils.convertDpToPixel(20f)); mCenterTextPaint.setTextAlign(Align.CENTER);
然後使用「\ n」作爲分裂拿到第一線
int index = centerText.indexOf("\n");
Spannable tempSpannable = new SpannableString(centerText);
tempSpannable.setSpan(new RelativeSizeSpan(0.75f), 0, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tempSpannable.setSpan(new ForegroundColorSpan(Color.parseColor("#999999")),
0, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// If width is 0, it will crash. Always have a minimum of 1
mCenterTextLayout = new StaticLayout(tempSpannable, 0, centerText.length(),
mCenterTextPaint,
(int)Math.max(Math.ceil(mCenterTextLastBounds.width()), 1.f),
Layout.Alignment.ALIGN_NORMAL, 1.f, 0.f, false);
PieData data = new PieData(dataSet);
pieChart.setCenterText("Total Questions 5");
pieChart.setCenterTextSize(14f);
pieChart.setCenterTextColor(Color.BLUE);