なんらかのカウンターを使用して、リスト ビュー内の要素を単純に繰り返すことができます。
int count = listView.getCount();
for (int i = 0; i < count; i++) {
listView.post(new Runnable() {
@Override
public void run() {
listView.smoothScrollToPosition(i);
}
});
}
// Once the method gets to here, i == count and we're at the last position
// So you can use some logic to scroll back to the top e.g.
// listView.smoothScrollToPosition(0)
を使用する代わりに、代わりにオブジェクトpost()
を使用することを検討することをお勧めしますTimer
。これは、ポスト キューの runnable がいつ実行されるかについてあまり制御できないと考えているためです。
編集
だから私はTimer
、固定レートのスケジュールされたScrollTimerTask
//This is an inner class, with i an int in the Activity, starting at 0;
public class ScrollTimerTask extends TimerTask {
@Override
public void run() {
if (i < getListView().getCount()) {
getListView().smoothScrollToPosition(i);
i++;
}
else {
getListView().smoothScrollToPosition(0);
i == 0;
}
}
次に、リストを下に移動し始める場所を呼び出しますnew Timer().scheduleAtFixedRate(new ScrollTimerTask(), 0, 1000);
。これにより、遅延なくスクロールが開始され、1000 ミリ秒ごとにスクロール タスクがスケジュールされます。
これは初歩的なものであり、アクティビティを閉じるとクラッシュし、継続的に実行されることに注意してください。クラッシュを防ぐために、Timer
オブジェクトへの参照を保持Timer.cancel()
し、Activity の onPause() メソッドを呼び出すことをお勧めします。しかし、それはスターティングブロックです!