tv_text.text="This is a piece of content" //Calculate the height and number of lines, etc. It cannot be obtained directly, and the value obtained directly is 0
tv_text.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { Log.e("TAG", "number of homeToday lines" + tv_text.getLineCount()) tv_text.getViewTreeObserver().removeGlobalOnLayoutListener(this) if ( tv_text.getLineCount() > 0) { tv_text.getViewTreeObserver().removeOnGlobalLayoutListener(this) } val lines =tv_text.getLineCount() //Refresh UI assignment in processing logic } })