textview获取宽度及文字宽度是否换行

//获取文字所占宽度
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时,一行就能展示下,反之需要换行

猜你喜欢

转载自blog.csdn.net/qq_25462179/article/details/125377317
今日推荐