Reputation: 787
Does anyone know a way to create a scrollview that when the end is reached, the next item will be the first item? Internet Explorer it will be more like a the wheel.
I have a horizontal scrollview wrapping a linear layout filled with pics and of course I can scroll from the beginning to the end and back but does anyone know a way to allow the scrolling to go in either direction infinitely and never reach an end?
Upvotes: 2
Views: 1295
Reputation: 17800
Use a ListView instead of a ScrollView. You can then keep your collection of items in an array. You'll have to create your own adapter that returns the (n % size)th element for index n.
You'll also need to add an OnScrollListener to your ListView that checks to see if the first and/or last elements in the list are visible. If so, you'll want to "grow" the size of your adapter by incrementing the returned size (not the internal size) by the original size.
A possible problem you may face is maintaining the correct scroll position in the ListView after the adapter grows. You may need to check the position of the first visible element before resizing the adapter and then scroll to this same position afterward.
Keep in mind that continuous scrolling will consume more and more memory until your layout is unresponsive.
Upvotes: 1