Android 简单的滑动手势活动教程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11833504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple swipe gesture to activity tutorial?
提问by Moussa
im looking for a turoial with source code on swipe gesutes, I dont want a view pager, I want a swipe gesture tutorial. here is one example I found but doesnt work for me
我正在寻找一个带有滑动手势源代码的教程,我不想要一个视图寻呼机,我想要一个滑动手势教程。这是我找到的一个例子,但对我不起作用
http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events
http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events
I would like something like this, thanks Please no view pagers
我想要这样的东西,谢谢 请不要查看寻呼机
采纳答案by Code Droid
SimpleOnGestureListener mySimpleGestureListener = new SimpleOnGestureListener()
{
@Override
public boolean onDoubleTap(MotionEvent e) {
Logout.debug("onDoubleTap");
return super.onDoubleTap(e);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)
{
String velocity="onFling: \n" + e1.toString() + "\n" + e2.toString() +"\n"
+ "velocityX= " + String.valueOf(velocityX) + "\n"
+ "velocityY= " + String.valueOf(velocityY) + "\n";
Logout.debug("onFling velocity="+velocity);
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public void onLongPress(MotionEvent e) {
Logout.debug("onLongPress: \n" + e.toString());
super.onLongPress(e);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Logout.debug("onSingleTapConfirmed: \n" + e.toString());
return super.onSingleTapConfirmed(e);
}
private boolean permissibleYVelocity(float velocityY)
{
if ((velocityY < -200) || (velocityY > 200))
{
return false;
}
else
{
return true;
}
}
};
GestureDetector myGestureDetector = new GestureDetector(mSimpleOnGestureListener);
View.OnTouchListener mOnListTouchListener = new OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent event)
{
Logout.debug("list onTouch()");
return myGestureDetector.onTouchEvent(event);
}
};
回答by Sindre
I would start by googling something like "Android basic swipe gesture". That was kinda what I did, and I ended up with this populare post on the subject: Fling gesture detection on grid layout
我首先会在谷歌上搜索“Android 基本滑动手势”之类的内容。这就是我所做的,最后我写了一篇关于这个主题的流行帖子:网格布局上的手势检测
First hit on google was this: http://pcfandroid.wordpress.com/2011/07/17/swipe-with-android-android-tutorial/, also applicable for you're question
谷歌的第一次点击是:http: //pcfandroid.wordpress.com/2011/07/17/swipe-with-android-android-tutorial/,也适用于你的问题