Android Question How to add elements in a ScrollView at the top?

FrankBerra

Active Member
Licensed User
Longtime User
Hi there
i am trying to develop a very simple messaging sytem: sending and receiving simple text messages (like whatsapp or viber, but really simple)
I can send, receive and display messages. Everything works nicely.

My problem is when i want to display the conversation i read from the file all the messages and display them in a scrollview (Every displayed message have label, panel, baloons, etc for looking better)
I am trying to optimize the loading of messages so instead of reading the whole file i want to read only some messages (for example 10 at time) and then read other messages only if the user needs them.

For adding messages at the bottom of the scrollview there is no problem, but how to add messages at top of the scrollview so i can scroll up continuosly and show past messages (like whatsapp/viber do)?

Thanks in advance for any suggestion
 

KMatle

Expert
Licensed User
Longtime User
I would put the newest first and by scrolling down just add 10 more labels and make the scrollview's panel bigger (label's hight + space between) * 10. There won't be an size problem (a few 1000 should work as long as you don't show pictures).

Another way is to swap the content of the labels (text's) so you don't need to remove views.

There are some libs here to do that. Ususally they simulate an endless scrolling by just swapping the content. But for learning reasons I would first try it on your own.
 
Upvote 0
Top