Hi All,
I am designing an native custom article view in android. My requirement is
such that I have a "long" text which i need to break into pages. I can
find out the total height of my TextView, how do i calculate the max
visible lines for the view based on the height?
I know Paint.breakText will do for me, but its very slow. Please have a
look at the following code snippet:
public static int getTextLineCountForHeight(String text, int maxWidth,
float textSize, Typeface typeface, int maxHeight) {
TextPaint paint = new TextPaint(Paint.LINEAR_TEXT_FLAG |
Paint.SUBPIXEL_TEXT_FLAG);
paint.setTextSize(textSize);
paint.setTypeface(typeface);
int lineCount = 0;
int index = 0;
int length = text.length();
Rect bounds = new Rect();
bounds.setEmpty();
while(index < length - 1) {
bounds.setEmpty();
index += paint.breakText(text, index, length, true, maxWidth, null);
lineCount++;
paint.getTextBounds("Py", 0, 2, bounds);
if((int)Math.floor(lineCount * bounds.height())>=maxHeight){
return lineCount;
}
}
return lineCount;
}
Can someone please suggest me some faster was to achieve my requirement.
Any help is highly appreciated.
-Ankur.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.