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姿势应该如下
但是无论怎么在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(); } });
相关文章推荐
- android TextView getlinecount返回0
- 关于Textview的getLineCount返回0
- Android获取TextView行数getLineCount()返回0
- Textview的getLineCount返回0
- abdroid关于TextView.getLineCount() 为0
- android 关于TextView getLineCount() 获得的值始终为0问题
- 获取TextView每行的内容 (涉及getLineCount为0,getLineEnd问题)
- 关于TextView getLineCount问题
- 获取listview中的子元素view, 设置textview的图标:setCompoundDrawables使用, view.textView.getHeight()为0
- getCountLine() 为0的问题
- Adapter的getViewTypeCount和getItemViewType
- Android ListView的不同样式,getItemViewType,getViewTypeCount
- 【已解决】Android中xml中TextView引用已定义好的样式时出错:android.view.InflateException: Binary XML file line #14: Error
- Adapter的getViewTypeCount和getItemViewType
- android listview多种布局 getViewTypeCount和getItemViewType
- UIButton return(textField textView)
- Listview item里面的textView.setMovementMethod(LinkMovementMethod.getInstance()) 让listview 点击生效解决方法
- 去除TextView设置lineSpacingExtra后,最后一行多出的空白
- 在viewPager中的textview参数singleLine和gravity为center冲突bug