private fun getLabelWidth(): Int {
val view = LayoutInflater.from(context).inflate(R.layout.view_vehicle_service_item, null)
val textView = view.findViewById<TextView>(R.id.vehicle_service_tv)
val spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
textView.measure(spec, spec)
return textView.measuredWidth
}
使用kotlin val textView=new TextView(context)
创建 textview时 上述代码不生效