get Text Length during layout - Android android.net

Android examples for android.net:Uri

Description

get Text Length during layout

Demo Code

import android.text.Layout;
import android.text.TextPaint;
import android.widget.TextView;

public class Main {

  public static int getTextLen(TextView textView) {
    TextPaint paint = textView.getPaint();
    return (int) Layout.getDesiredWidth(textView.getText().toString(), 0, textView.getText().length(), paint);
  }//  w w  w. java  2 s . co  m

}

Related Tutorials