I want to automatically scroll the horizontal scroll that contains a lot of images in linear mode when it reaches the last image, the first appears, etc.
I found this code that suits my needs, but when I added automatic scrolling, the circular function will not work: when the last image is reached, the first will not appear
here is my code:
slider = (RelativeLayout)findViewById(R.id.slider);
RelativeLayout container = (RelativeLayout) findViewById(R.id.slider);
scrollView = new PSInfiniteScrollView(this,new PSSize(120,120));
for (int i = 0; i < 10; i++) {
MyCloneableView img = new MyCloneableView(this);
img.setId(i + 20);
img.setImageResource(R.drawable.ic_launcher);
img.setScaleType(ImageView.ScaleType.FIT_XY);
img.setBackgroundColor(c[i]);
img.setTag(c[i]);
scrollView.addItem(img);
}
container.addView(scrollView);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
doLoop();
}
});
t.start();
and here is the doLoop method:
private void doLoop(){
do {
scrollView.scrollBy(2, 0);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
scrollView.scrollBy(2, 0);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (true);
}
source
share