![]() ![]() font and you want the next line to be larger, set that to 16 pt. ![]() A best practice is to differentiate text sizes by at least 4 points. Michael Scheper's solution seems nice but it didn't work for me, I needed to get the largest text size that is possible to draw in my view but this approach depends on the first text size you set, Every time you set a different size you'll get different results that can not say it is the right answer in every situation. If you’d like one line, section, or word to appear in a larger font, just set the font size for the section to a larger size. However, this may introduce concurrency issues, and would arguably hinder code clarity. Then, all you need to do is setTextSizeForWidth(paint, 400, str) (400 being the example width in the question).įor even greater efficiency, you can make the Rect a static class member, saving it from being instantiated each time. Calculate the desired size as a proportion of our testTextSize.įloat desiredTextSize = testTextSize * desiredWidth / bounds.width() Paint.getTextBounds(text, 0, text.length(), bounds) ![]() Get the bounds of the text, using our testTextSize. But there are workarounds for that, too refer to more accurate results, but may cause problems with hardware Pick a reasonably large value for the test. Private static void setTextSizeForWidth(Paint paint, float desiredWidth, * Sets the text size for a Paint object so a given string of text will be a ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |