问题
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