//获取文字所占宽度 var spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); tv_textcontent.measure(spec, spec); var textPaint = tv_textcontent.getPaint(); var textPaintWidth = textPaint.measureText(str);
var textwidth=px2dp(mContext, tv_textcontent.width.toFloat())//text控件宽度 var mwidth=px2dp(mContext, textPaintWidth)//字符串文字所需宽度
//当 textwidth大于mwidth时,一行就能展示下,反之需要换行