given a string in resources, how can I get the bounding rectangle for it?
For plain text, I could use Paint.getTextBounds(), but this is a string from resources that has newlines and attribute settings in it.
<string name="foobar"><small>Foo</small>\nBar</string>
In other words, I’m implementing a custom view that will be displaying a string like that, and I want to compute the size of my view.
More detail: Basically, I’m implementing a variant of TextView that adjusts its font size to fit the available space rather than one that adjusts its size to fit the text.
You want to show html in your custom view. Do i make it clear?
If you want to implements this all by your own code. It is a very huge work. Extending TextView and overriding some methods is the best choice, but if you insist on writing your own class, you can still get help from some system class.
Showing and measuing html should follow the code of TextView, you can find this in TextView.onDraw() and TextView.onMeasure(), here i just talk about the steps for measuring html.
Html.fromHtml()to get a Spanned text.StaticLayoutorDynamicLayoutwith the spanned text.Layout.getLineWidth()andLayout.getHeight()to measure the text.