CircleProgressBar icon indicating copy to clipboard operation
CircleProgressBar copied to clipboard

How to have text and % on two different lines?

Open n0490b opened this issue 6 years ago • 3 comments

I've tried \n but it doesnt work. Is it possible to have two lines of text?

n0490b avatar Apr 21 '18 20:04 n0490b

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.

emre1512 avatar Apr 21 '18 20:04 emre1512

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"/>

n0490b avatar Apr 21 '18 20:04 n0490b

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.

emre1512 avatar Apr 22 '18 08:04 emre1512