Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have text and % on two different lines? #3

Open
n0490b opened this issue Apr 21, 2018 · 3 comments
Open

How to have text and % on two different lines? #3

n0490b opened this issue Apr 21, 2018 · 3 comments

Comments

@n0490b
Copy link

n0490b commented Apr 21, 2018

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

@emre1512
Copy link
Owner

emre1512 commented Apr 21, 2018

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.

@n0490b
Copy link
Author

n0490b commented Apr 21, 2018

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

@emre1512
Copy link
Owner

emre1512 commented Apr 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants