How to use textview.getLayout()? It returns null

后端 未结 6 2005
孤独总比滥情好
孤独总比滥情好 2020-12-01 10:50

I’m trying set a layout for textview so I can use getEllipsisCount() method. But below code returns null as layout value. How can I take layout and

6条回答
  •  遥遥无期
    2020-12-01 11:28

    From the documentation:

    public final Layout getLayout ()

    Added in API level 1 Returns the Layout that is currently being used to display the text. This can be null if the text or width has recently changes.

    So probably your text has changes or you call it too early.

    Look at this answer where is stated

    This only works after the layout phase, otherwise the returned layout will be null, so call this at an appropriate place in your code.

提交回复
热议问题