multiple text views or one text view with clickable spans?

前端 未结 1 472
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 01:29

I have an array of models each representing a word in a text. It looks like this:

ArrayList text;

class Word {
    public String name;
    public bo         


        
相关标签:
1条回答
  • 2021-01-28 01:48

    I would suggest you use one TextView as this is a much more efficient UI. When there is a request for a ViewGroup to measure all of it's children, it is much faster to measure only one than a couple of thousand.

    I have found a nice library you may try to use here. It uses getOffsetForPostion method added to TextView in API level 14.

    public int getOffsetForPosition (float x, float y)

    Added in API level 14 Get the character offset closest to the specified absolute position. A typical use case is to pass the result of getX() and getY() to this method.

    Parameters x The horizontal absolute position of a point on screen y The vertical absolute position of a point on screen Returns the character offset for the character whose position is closest to the specified position. Returns -1 if there is no layout.

    0 讨论(0)
提交回复
热议问题