1. 程式人生 > >Android TestView獲取每一行文字的方法

Android TestView獲取每一行文字的方法

艾瑪呀,累死我了,終於找到了方法了,em親測有效

Layout layout = textView.getLayout();
String text = textView.getText().toString();
int start = 0;
int end;
//迴圈遍歷列印每一行
for (int i = 0; i < textView.getLineCount(); i++) {
    end = layout.getLineEnd(i);
String line = text.substring(start, end); //指定行的內容
start = end;
Log.d("MyTextView"
, "setMyText: line " + line); }