I'm trying to implement a slot machin with 3 endless ListView. I wanted to do that with scroll view but I didn't find a solution to loop on a scrollView.
So basically I have three listview = 3 columns of my slot machine and when I click on button I want to scroll to a random position (a random integer between 0 (inclusive) and 300 (exclusive) which is my lists size) :
Random r = new Random();
int rPos1 = r.nextInt(300 - 0) +0;
int rPos2 = r.nextInt(300 - 0) + 0;
int rPos3 = r.nextInt(300 - 0) +0;
listSlotOne.smoothScrollToPosition(rPos1);
listSlotTwo.smoothScrollToPosition(rPos2);
listSlotThree.smoothScrollToPosition(rPos3);
So all this part is working but I can't manage to display each time as a result a clean result which mean three aligned lines on my screen ::
Here a good result : three aligned lines
Here a bad result : lines are not aligned
Is it possible to manage the behaviour of my random scroll to display every time a good result : three aligned lines. I've noticed, for my 3 click on the play button I got a good result but after a fourth click I get a wrong result with not lines aligned and then it's random.
If the smoothScrollToPosition() method doesn't snap, you are going to have to add your own snap meaning something like:
or listSlotOne.smoothScrollToPosition((rPos1 / snap_height) * snap_height); listSlotTwo.smoothScrollToPosition((rPos2 / snap_height) * snap_height); listSlotThree.smoothScrollToPosition((rPos3 / snap_height) * snap_height);
I may be wrong, I'm not 100% sure but I believe that will solve your problem.
Snap To Grid I remember doing it with MOD though... well maybe this will help.
Cheers,
Demetry