Android判断是否触发ellipsize="end"(即textview是否换行)
16lz
2021-01-23
代码如下:
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控件开发之四----ListView(1)
- Android控件属性大全[整理]
- Android控件开发
- Android 调用相册 拍照 实现系统控件缩放 切割图片
- android 自定义时间控件
- Android软键盘弹出时把布局顶上去,控件乱套解决方法