MPAndroidChart PieChart how to change the center text to display the different color and font size

后端 未结 4 1468
轮回少年
轮回少年 2021-02-11 07:36

Currently I use the MPAndroidChart from GITHUB and draw the piechart to display the two line text, each line has different color and different font size,I check the source codes

4条回答
  •  失恋的感觉
    2021-02-11 07:49

    after study the source codes, i change the PieChartRenderer.java to change the mCenterTextPaint.setColor(Color.parseColor("#333333")); mCenterTextPaint.setTextSize(Utils.convertDpToPixel(20f)); mCenterTextPaint.setTextAlign(Align.CENTER);

    then use the "\n" as a split to get the first line

       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);
    

    then get what i wanted is

提交回复
热议问题