Am 13.02.14 03:54, schrieb Ankur Avlani:
> Can someone please suggest me some faster was to achieve my requirement.

try this one:

/**
 * Calculates the lines needed to show the text.
 *
 * @param paint
 *           the TextPaint from the TextView
 * @param text
 *           the text for the calculation
 * @param textAppearance
 *           text typeface, size, and style
 * @param avail
 *           the available width
 * @return the number of lines needed to show the text
 */
public static int neededLines(final TextPaint paint, final String text,
final TextAppearanceSpan textAppearance, final int avail) {

   if (TextUtils.isEmpty(text)) {
      return 0;
   }

   final TextPaint textPaint = new TextPaint();
   textPaint.set(paint);

   textPaint.setTextSize(textAppearance.getTextSize());
   textPaint.setTypeface(Typeface.create(textAppearance.getFamily(),
textAppearance.getTextStyle()));

   final StaticLayout layout = new StaticLayout(text, textPaint, avail,
Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
   final int lineCount = layout.getLineCount();

   return lineCount;
}



Ralph

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to