美文网首页
获取textview的宽度

获取textview的宽度

作者: 喜爱滴小麦芽 | 来源:发表于2018-08-11 11:43 被阅读13次

今天用到了记录下
当TextView的属性是wrap_content时,如何获取其宽度,特别是在界面还没显示时,比如像在RecycleView中的情况?

TextView tv_name = findViewById(R.id.tv_name); tv_name .setText(str);
int spec=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
tv_name.measure(spec,spec);
int measuredWidthTicketNum = tv_name.getMeasuredWidth();

参考 https://blog.csdn.net/xiaoshuang516/article/details/51510361

相关文章

网友评论

      本文标题:获取textview的宽度

      本文链接:https://www.haomeiwen.com/subject/mmxdbftx.html