android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
2016-08-05 10:24
741 查看
布局文件中的TextView属性
在JAVA代码中控制文本的显示行数
<TextView android:id="@+id/businesscardsingle_content_abstract" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:lineSpacingMultiplier="1.0" android:lines="6" android:text="@string/agrinbusiness_content" android:textColor="#7f7f7f" android:textSize="13sp" />
在JAVA代码中控制文本的显示行数
ViewTreeObserver observer = textAbstract.getViewTreeObserver(); //textAbstract为TextView控件 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewTreeObserver obs = textAbstract.getViewTreeObserver(); obs.removeGlobalOnLayoutListener(this); if(textAbstract.getLineCount() > 6) //判断行数大于多少时改变 { int lineEndIndex = textAbstract.getLayout().getLineEnd(5); //设置第六行打省略号 String text = textAbstract.getText().subSequence(0, lineEndIndex-3) +"..."; textAbstract.setText(text); } } });
相关文章推荐
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize="end"属性无效问题的解决方法
- android TextView多行文本(超过3行)使用ellipsize属性无效
- Android使用TextView,设置onClick属性无效解决的方法
- Android使用TextView,设置onClick属性无效的解决方法
- Android使用TextView,设置onClick属性无效解决办法
- Android使用TextView,设置onClick属性无效解决办法
- Android TextView使用SpannableString设置复合文本的方法详解
- Android textview 加载html语言(解决超链接不能使用的问题)
- 彻底解决android中Textview控件文本自动换行问题
- android 获取网络数据,回传到本地用TextView显示乱码问题解决方法
- 安卓中经常使用控件遇到问题解决方法(持续更新和发现篇幅)(在textview上加一条线、待续)
- 解决TextView数据不能更新的问题以及Android Button事件响应函数的两种方法
- Android编程中TextView宽度过大导致Drawable无法居中问题解决方法
- Android控件TextView中ellipsize属性(设置当文字长度超过textview宽度时的显示方式)
- android文本组件textView属性autolink设置为web,显示网址的处理方法
- android 开发:使得TextView文本左右两边都对齐--解决中英文对齐问题。