Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
you can use "textPaint.getTextSize()" to get text width
Well I have done in different way:
Hope this will help you.
Supplemental answer
There is a slight difference between the width returned by
Paint.measureText
andPaint.getTextBounds
.measureText
returns a width that includes the glyph's advanceX value padding the beginning and end of the string. TheRect
width returned bygetTextBounds
does not have this padding because the bounds is theRect
that tightly wraps the text.source
Have you looked at android.graphics.Paint.measureText(String txt)?
I used the methods measureText() and getTextPath()+computeBounds() and build up an Excel with all text attributes for fixed size font that can be found under https://github.com/ArminJo/android-blue-display/blob/master/TextWidth.xlsx . There you will find also simple formulas for other text attributes like ascend etc.
The app as well as the function drawFontTest() for generating the raw values used in the excel are also available in this repo.