您的位置:首页 > 其它

TextView Get Line Count Return 0?

2015-05-14 16:39 363 查看
想给TextView加上个“展开/收起”的功能,思路是这样的,给TextView限制maxLine为4行,当getLineCount() >=4时,显示“展开”按钮。
但是无论怎么在textView#setText 之前还是之后去getLineCount()都返回的“0”…..
仔细“领会”了一番doc:

Return the number of lines of text, or 0 if the internal Layout has not been built.

原因应该是内部的布局还没有绘制完毕,我就去getLineCount()了,当然会返回0咯。
正确的get姿势应该如下
mTextView.setText("large text");
mTextView.post(new Runnable() {
@Override
public void run() {
int lineCount = mTextView.getLineCount();
if(lineCount >=4)
showDetailButton();
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: