-2

I want to make a gridView (or ListView) scrolling automatically (without user interaction) repeatly.

I want it on the background, the user has not the possibility to scroll the gridView, he has only one button in foreground to start an activity. It is just a "presentation" activity

How can I make it possible? I have no idea what to use to do it, if there is somes simple android api to make it. Should I use animation thread or can it be done only with smoothToScroll?

Chol
  • 2,097
  • 2
  • 16
  • 26

2 Answers2

1

You have the smoothScrollToPosition method that will scroll to a position on the listview/gridview

http://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int)

As for the possibility to scroll on the gridview/listview just implement a touchListener and return true

For example if you want to to this slowly you can't just create a for. It will scroll too fast. You can use handlers for that. Create a recursive function scrollTo.

public void scrollTo(final ListView myView, final int position) {
    final Handler myHandler = new Handler();
    myHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            myView.smoothScrollToPosition(position);
            if(position<myView.getAdapter().getCount())
                scrollTo(myView, position + 1);
        }
    }, 2000);
}

And next call it once like scrollTo(myListview,0);. The function will do the rest. Change 2000 for the number of seconds you want to wait *1000.

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • Ok for the touchListener! I'm not sur how to use the smoothScrollToPosition. Do i need to scroll pixel by pixel? do I need to do it on an asyncTask? – Chol Oct 31 '14 at 10:23
  • No. It receives a position. Position of the item you want to scroll to. If you want to scroll to the 3rd item just call `smoothScrollToPosition(3);`. Did you read the link I posted too? It's all explained there. – Pedro Oliveira Oct 31 '14 at 10:24
  • My bad... I get it! I have done this: for (int i=0; i – Chol Oct 31 '14 at 10:29
  • With your scrollTo method it seems to scroll to the same speed (quick). The 2000 number only seems to be the time to start the scroll. The Siva answer seems to work, with duration it scroll slowly – Chol Oct 31 '14 at 10:52
  • But you want to scroll slowly or you want to scroll after some time to the next item? It's a diferent approach. If you want to scroll slowly then you need to use the duration. If want to scroll to next item after a while you will have to do it with handlers. What do you want? – Pedro Oliveira Oct 31 '14 at 11:03
1

Use duration

mListView.smoothScrollToPositionFromTop(position, duration);
Siva
  • 446
  • 2
  • 9
  • 24