How to get number of lines of TextView?

前端 未结 10 2487
萌比男神i
萌比男神i 2020-11-28 09:29

I want to get the number of lines of a text view

textView.setText(\"Test line 1 Test line 2 Test line 3 Test line 4 Test line 5.............\")
10条回答
  •  臣服心动
    2020-11-28 10:17

    You can also calculate the amount of lines through this function:

    private fun countLines(textView: TextView): Int {
            return Math.ceil(textView.paint.measureText(textView.text.toString()) /
                    textView.measuredWidth.toDouble()).toInt()
        }
    

    Keep in mind that It may not work very well on a RecyclerView though.

提交回复
热议问题