获取textview的宽度

 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时 上述代码不生效

猜你喜欢

转载自blog.csdn.net/genmenu/article/details/105786967