Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recycling views in scroll view

I have an app that show the tv guide for a list of channels. My UI is made from a a lot of custom views with different widths that show the tv programs, all these custom views are added into a horizontal scrollview that is added into a scrollview so my views can be scroll in 2 dimensions left-right and top-down. It all works good until i add add a lot of views and it starts to slow down very much. So i need a way to recycle views like listiew does in a scrollview maybe there is a custom made scrollview that does this, or someone has an idea how to do this, its strange that scrollview isnt backed up by an adapter like gridview and listview.

This is how my UI looks

like image 982
user924941 Avatar asked May 06 '13 17:05

user924941


People also ask

Is recycler view scrollable?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .

What is the difference between RecyclerView and ScrollView?

In the practical on scrolling views, you use ScrollView to scroll a View or ViewGroup . ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists.

Why is RecyclerView not scrolling?

Why Recycler view not scrolling? To fix this issue, all you have to do is add this line after RecyclerView s adapter has been set. ViewCompat. setNestedScrollingEnabled(listRecyclerView, false); Now, your RecyclerView will work with smooth scrolling.


1 Answers

I did something similar only my Views were not connected as yours but they were all different sizes.

First you need to define if your entire area (not just viewing screen) has definitive or dynamical number of your custom views.

If you have definitive number of views and their positions you should create their position map with list of Rect's (Rect has a good function whether the xy point belongs). Then you define maximum of Views which are visible on your screen. For this to work without constant loading you should have maximum visible views + at least one line of border views of total objects. After all this you should easily have your own positioning system where you load views which are in bounds of your screen + some overhead (purpose of this is that you want your users to have smooth transition while scrolling at least for some length), if you need to load some in same time you unload (read reuse/ do not dispose objects and create them onScroll events) and place them according to your needs.

And if you want to determine which views should be visible you just go through list and ask whether Views Rect intersects with your Rect of area to be loaded.

Hope this image helps a little bit more

Example

I know it sounds a little bit confusing and difficult to implement but you did not asked a simple question :) Hope this helps and enjoy your work.

like image 130
Marko Lazić Avatar answered Oct 30 '22 11:10

Marko Lazić