本文介绍了下一张和上一张图片通过 swipe s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 android 新手,正在开发一个漫画应用程序.我正在使用此代码访问https://github.com/sephiroth74/ImageViewZoom 用于捏缩放.并且工作得很好.
i am new in android and working a comic application.i am using this code visithttps://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 uplease any expert give me a bit time .
推荐答案
您可以像这样在主视图上检测投掷手势:
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;
}
}
});
这篇关于下一张和上一张图片通过 swipe s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!