CircleProgressBar
CircleProgressBar copied to clipboard
How to have text and % on two different lines?
I've tried \n
but it doesnt work. Is it possible to have two lines of text?
With a quick stackoverflow search I found that you can use <br>
instead of \n
. Or try using \r\n
. You can check https://stackoverflow.com/questions/2840608/how-do-i-add-a-newline-to-a-textview-in-android for more. Let me know if one of these work.
Hi, sorry I should have mentioned that I did try those. Using <br>
throws an error, and \r\n
doesn't work. It shows the "r". Here is how I'm trying
<com.emredavarci.circleprogressbar.CircleProgressBar
xmlns:cpb="http://schemas.android.com/apk/res-auto"
android:id="@+id/progressBar"
android:layout_width="150dp"
android:layout_height="150dp"
cpb:progressColor="#e76130"
cpb:backgroundColor="#e7b330"
cpb:strokeWidth="14"
cpb:backgroundWidth="8"
cpb:textSize="18sp"
cpb:roundedCorners="true"
cpb:suffix="%"
cpb:prefix=""
cpb:progressText="Loading...\r\n"
cpb:maxValue="100"
cpb:progressTextColor="#f9916b"/>
Ok, so it is not working because the text is not a TextView
, it is a Paint
. I did not think someone will need new line in text. To achieve this I can make an improvement at line 154 at https://github.com/emre1512/CircleProgressBar/blob/master/app/src/main/java/com/emredavarci/circleprogressbar/CircleProgressBar.java
This line should be something like this:
for (String line: text.split("\n")) {
textHeight += textPaint.descent() - textPaint.ascent();
canvas.drawText(drawnText, (getWidth() - textPaint.measureText(drawnText)) / 2.0f, (getWidth() - textHeight) / 2.0f, textPaint);
}
I did not try it yet and can not make the improvement soon. But this issue will stay open as enhancement.