如何找出Android上文本视图中文本换行的行数?

如何找出Android上文本视图中文本换行的行数?,android,string,text,textview,word-wrap,Android,String,Text,Textview,Word Wrap,我有一个长字符串,它可以换行到多行,行数根据所使用的Android设备的大小而不同。有没有办法知道文本换行到多少行?您可以使用以下类别之一: “有没有一种方法可以用XML来实现这一点?”披头士-我不这么认为。在编译xml时,系统无法知道它将在哪些设备上运行。 Layout layout = new StaticLayout(text, /* other stuff--see docs */); int nLines = layout.getLineCount();

我有一个长字符串,它可以换行到多行,行数根据所使用的Android设备的大小而不同。有没有办法知道文本换行到多少行?

您可以使用以下类别之一:


“有没有一种方法可以用XML来实现这一点?”披头士-我不这么认为。在编译xml时,系统无法知道它将在哪些设备上运行。
Layout layout = new StaticLayout(text, /* other stuff--see docs */);
int nLines = layout.getLineCount();