Show multiple images in a imageView one after another with left to right flip effect repeatedly

后端 未结 6 1314
天命终不由人
天命终不由人 2021-02-09 20:16

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(

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-09 20:55

    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;
    }
    }
    

提交回复
热议问题