I am looking for a method in Android that will accept input (text, text_font_size, device_width), and based on these calculations, it will return how much height will it take to display specific text?
I set the time for viewing the text view / web view based on its contents, I know about the contents of warp, but I can not use it in my case due to some problem with the minimum height of the web view.
So, I'm trying to calculate the height and based on this I set the height of the view.
I tried the following methods:
Paint paint = new Paint(); paint.setTextSize(text.length()); Rect bounds = new Rect(); paint.getTextBounds(text, 0, 1, bounds); mTextViewHeight= bounds.height();
Thus, the conclusion
1) "Hello World" returns a height of 13 for font 15
2) "The latest version of Jelly Bean here, with performance optimization" returns a height of 16 for font 15
Then i tried with
Paint paint = new Paint(); paint.setTextSize(15); paint.setTypeface(Typeface.SANS_SERIF); paint.setColor(Color.BLACK); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), result); Paint.FontMetrics metrics = brush.getFontMetrics(); int totalHeight = (int) (metrics.descent - metrics.ascent + metrics.leading);
Thus, the conclusion
1) "Hello World" returns a height of 17 for font 15
2) "The latest version of Jelly Bean here, with performance optimization" returns a height of 17 for font 15
if I set these values ββfor my view and then cut off some text without showing all the content.
Again it looks normal on some tables, as it has a large width, but not on the phone.
Is there any way to calculate height by content?
android android-layout android-textview android-canvas android-view
Mac Jan 11 '13 at 11:07 2013-01-11 11:07
source share