Search code examples
androidlayoutandroid-recyclerviewplaceholder

Recyclerview item-height changes after loading data


I use text spans in my app with ImageSpan and text. The text is parsed asynchronously and the ImageSpans are inserted/replaced accordingly. There might be one or more ImageSpans or none at all.

How can I calculate the size beforehand which the final text will take up with ImageSpans included?

The problem I have is, When I finally update the TextView in the RecyclerView item, the whole view "jumps". You can imagine with a lot of list items which are set at different times, the list would appear to be jumping.

enter image description here

I want to eliminate the "jump" by pre-setting the size of the TextView for when the text is displayed, the size of the item is not changed and the list doesn't jump.

Any help or suggestions would be much appreciated.


Solution

  • Since we have no idea about the size of text being loaded before it completes, the only option we have is to leave some area reserved for that text.Illustration: before and after loading

    This can easily be done by making either the TextView or one of it's parent (which is not the parent of known texts) fixed sized.



    These are also recommended:

    The placeholder can be simple dummy text or something more elegant like as in the image below.

    Skeleton library preview

    You can find this library here.