I have a LinearLayout inside a ScrollView and I want to create the ilusion of endless scrolling by removing the views that are not visible and putting them as the next elements in the list (basically i do a linearlayout.removeView(viewOutOfScreen)
and then linearlayout.addView(viewOutOfScreen)
. The problem is, every time this happens the view that is currently visible ends up in the top of the ScrollView. I tried doing a scrollView.scrollTo(0, -viewOutOfScreen.contentHeight)
and it kinda works but the transition generates an horrible tearing artifact.
Also I'm not able to use RecyclerView given that the views are WebViews with very specific settings and executing js, so i nedd to reutilize/reposition them manually (cant't create more than i initially have).
Asked
Active
Viewed 231 times
0

Jasper
- 1
2 Answers
0
I recommend using a nested RecyclerView
because, it does exactly what you are trying to achieve manually. It recycles views which are out of the screen.

Kl3jvi
- 105
- 2
- 10
-
I've tried using a `RecyclerView` following [this](https://www.geeksforgeeks.org/endless-recyclerview-in-android/) tutorial, but on the `loadMore()` function it creates more objects and adds them to the ArrayList. How can indicate to the `RecyclerView` that I want to populate the list with the previous views ? Also I don´t understand why it has to be nested as you pointed out ? I don´t need to scroll inside the individual webViews, they display the complete webpage. – Jasper Feb 13 '22 at 23:05
0
Also I'm not able to use RecyclerView given that the views are WebViews with very specific settings and executing js, so i nedd to reutilize/reposition them manually (cant't create more than i initially have).
So what if they're WebViews? You could just manually cache the views you want to display (ignoring the "recycling" part of RecyclerView) and return the View you want for each index instead of letting the RecyclerView delete and recreate them.

dominicoder
- 9,338
- 1
- 26
- 32
-
Well that's something I did not consider, given my quite limited understanding of `RecyclerView`. If you could give me a more detailed explanation it wold be much appreciated. Should I use `recylerViewAdapter.notifyItemInserted()` and `recylerViewAdapter.notifyItemRemoved()` ? I've followed [this](https://www.geeksforgeeks.org/endless-recyclerview-in-android/) tutorial but I don't know what I should do in the `loadMore()` function. – Jasper Feb 14 '22 at 02:41
-
Search around for "endless recyclerview" - this is something that has been asked and answered a lot. For example: https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview – dominicoder Feb 15 '22 at 22:12