next and previous image by swipe s

倾然丶 夕夏残阳落幕 提交于 2019-12-01 11:48:26
sdabet

You can detect fling gestures on your main view like this:

final GestureDetector detector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if(velocityX > 0) {
            selectnextImage();
        }
        else {
            selectpreImage();
        }
        return true;
    }
});

view.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getPointerCount() == 1) {
            if(mimage.getScale() == 1f) {
                detector.onTouchEvent(event);
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
});

Try looking at the Android documentation for Implementing Lateral Navigation. This uses a ViewPager. I believe this is what Google recommends for something like this. You may not want to have the tabs there, but you can implement it without tabs. You can also implement it with a FragmentPagerAdapter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!