今天用getLineCount()方法获取行高失败;
原因:
public int getLineCount ()
Since: API Level 1
Return the number of lines of text, or returns 0 if the internal Layout has not been built.
解决办法:
tv.setText("Text Here");
tv.post(new Runnable() {
@Override
public void run() {
int lineCount = tv.getLineCount();
Log.v("LINE_NUMBERS", lineCount+"");
}
});
本文详细介绍了在Android开发中使用getLineCount()方法获取TextView行高时遇到的问题及解决策略,通过调用setText()方法后立即调用post()方法来确保内部布局已构建,从而成功获取行数。
1万+

被折叠的 条评论
为什么被折叠?



