next and previous image by swipe s

╄→гoц情女王★ 提交于 2019-12-01 12:00:02

问题


i am new in android and working a comic application. i am using this code visit https://github.com/sephiroth74/ImageViewZoom for pinch zoom . and working it very fine.

but i am trying to go to next and previous image by swipe . but i am unable . this is my code which is OK for button and now i want to add swipe method .

next.setOnClickListener( new OnClickListener() {


        public void onClick( View v ) {
            selectnextImage();
        }
    } );

     pre.setOnClickListener( new OnClickListener() {
        public void onClick( View v ) {
            selectpreImage();
        }
    } );

thank u please any expert give me a bit time .


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/13162386/next-and-previous-image-by-swipe-s

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