Suppose I have multiple images in drawable folder(ex-8 images). I want to show all these images in a imageView one after another with left to right flip effect repeatedly(
Just use
public class CustomGallery extends Gallery {
private Handler handler;
public CustomGallery(Context context) {
super(context);
handler = new Handler();
postDelayedScrollNext();
}
public CustomGallery(Context context, AttributeSet attrs) {
super(context, attrs);
handler = new Handler();
postDelayedScrollNext();
}
public CustomGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
handler = new Handler();
postDelayedScrollNext();
}
protected void postDelayedScrollNext() {
handler.postDelayed(new Runnable() {
public void run() {
postDelayedScrollNext();
Log.d("CustomGallery", "dpad RIGHT");
onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
}, 1000);
}
protected boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
return e2.getX() > e1.getX();
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int kEvent;
if (isScrollingLeft(e1, e2)) {
Log.d("CustomGallery", "fling LEFT");
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
} else {
Log.d("CustomGallery", "fling LEFT");
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
}
onKeyDown(kEvent, null);
return true;
}
}