android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
布局文件中的TextView属性
<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设置中文字体加粗实现方法
- Android TextView设置背景色与边框的方法详解
- Android编程开发之TextView文字显示和修改方法(附TextView属性介绍)
- Android TextView字体颜色设置方法小结
- android实现上下滚动的TextView
- android TextView不用ScrollViewe也可以滚动的方法
- Android设置TextView显示指定个数字符,超过部分显示...(省略号)的方法
- Android中TextView显示圆圈背景或设置圆角的方法
- Android中TextView实现分段显示不同颜色的字符串
- Android 妙用TextView实现左边文字,右边图片
相关文章
Android实现TextView中文字链接的4种方式介绍及代码
Android实现TextView中文字链接的方式有很多种;总结起来大概有4种:用Spannable或实现它的类,如SpannableString来格式,部分字符串等等,感兴趣的你可以参考下2013-02-02


最新评论