The number of rows displayed by the textview in the item in the recycleView list

 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 
              
                        } 
                    })

Guess you like

Origin blog.csdn.net/qq_25462179/article/details/131837460