1.当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();
android TextView 如何动态获取宽度
最新推荐文章于 2024-08-12 11:42:49 发布