Android判断是否触发ellipsize="end"(即textview是否换行)
16lz
2022-03-13
代码如下:
private void TvOverFlowed(final TextView textView,final View img) {
ViewTreeObserver vto = textView.getViewTreeObserver();vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@Override
public void onGlobalLayout() {
textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
textView.getHeight();
double w0=textView.getWidth();//控件宽度
double w1=textView.getPaint().measureText(textView.getText().toString());//文本宽度
if(w1>=w0) img.setVisibility(View.VISIBLE);//需要换行就显示该控件
}
});
}
需要注意的是getWidth()的使用,这里有:http://www.bkjia.com/Androidjc/890740.html
更多相关文章
- Android(安卓)自定义设置文本字体间间距
- 【Android学习笔记】AutoCompleteTextView(数组在代码中)
- android-----EditText
- Android编程示例之——横竖屏切换动画
- Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
- Android自动提示文本框(AutoCompleteTextView)
- android 布局随笔----用户登录界面
- Android控件开发之四----ListView(1)
- Android控件属性大全[整理]