今天用到了記錄下
當(dāng)TextView的屬性是wrap_content時(shí)者冤,如何獲取其寬度缤底,特別是在界面還沒(méi)顯示時(shí),比如像在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