道客优

1234
TextView获取指定行文字
2019-02-26 刀刻油 阅读:985

ViewTreeObserver vto =tvHotTopicDescribe.getViewTreeObserver();

vto.addOnGlobalLayoutListener(newViewTreeObserver.OnGlobalLayoutListener() {

@Override

public voidonGlobalLayout() {

Layout layout =textview.getLayout();

intline ==textview.getLayout().getLineCount();

String result ="";

String text = layout.getText().toString();

for(int i=0;i

int start=layout.getLineStart(i);

int end=layout.getLineEnd(i);

result+=text.substring(start, end)+"\\n";

}

int start=layout.getLineStart(line-1);

int end=layout.getLineEnd(line-1);

result+=text.substring(start, end);

});



推荐阅读: