tv_text.text=“这是一段内容”//计算高度和行数等 不能直接获取,直接获取的值为0
tv_text.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { Log.e("TAG", "homeToday行数" + tv_text.getLineCount()) tv_text.getViewTreeObserver().removeGlobalOnLayoutListener(this) if (tv_text.getLineCount() > 0) { tv_text.getViewTreeObserver().removeOnGlobalLayoutListener(this) } val lines =tv_text.getLineCount() //在处理逻辑刷新UI 赋值等 } })