一: GestureDetector
http://blog.csdn.net/jjwwmlp456/article/details/21282239 写的不错,但是
博文中有错误,正确的写法是:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX()-e2.getX()>120) {//左滑,右边显示
ToastUtils.showShortToast(PersonalCenterActivity2.this, "左滑,右边显示");
}
if(e1.getX()-e2.getX()<-120) {
ToastUtils.showShortToast(PersonalCenterActivity2.this, "右滑,左边显示");
}
return false;
}
http://www.cnblogs.com/ok-lanyan/archive/2012/08/02/2619701.html
二:Android的Activity屏幕切换动画(一)-左右滑动切换:
http://www.oschina.net/question/97118_34343
三:android开发中Webview无法触发手势方法(ontouchevent,onfling...)的解决方法:
http://www.android100.org/html/201403/08/5830.html
@Override
public boolean dispatchTouchEvent(MotionEvent ev) { //注意这里不能用ONTOUCHEVENT方法,不然无效的
Toast.makeText(NewsContent.this, "jinru", 1).show();
detector.onTouchEvent(ev);
webview.onTouchEvent(ev);
return super.dispatchTouchEvent(ev);
}
适用与webview,scollview,listview。
Acitity中有listview,手势无法实现 :
http://www.apkbus.com/android-121113-1-1.html
Android Activity之间切换出现短暂黑屏的处理方法:
style name="startTheme" parent="@android:style/Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item><!--无标题-->
</style>
http://blog.csdn.net/toyuexinshangwan/article/details/8559253
四:上下左右滑动冲突问题:
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
double angle = Math.atan2(Math.abs(distanceY), Math.abs(distanceX));
// System.out.println("angle-->" + (180 * angle) / Math.PI);
if ((180 * angle) / Math.PI < 180) {
return false;
}
return false;
}
五、Android开发ScrollView上下左右滑动事件冲突整理二(根据角度)
http://zwnjava.iteye.com/blog/1698751
六、用Activity的onTouchEvent方法实现监听手指上下左右滑动:
@Override
public boolean onTouchEvent(MotionEvent event) {
//继承了Activity的onTouchEvent方法,直接监听点击事件
if(event.getAction() == MotionEvent.ACTION_DOWN) {
//当手指按下的时候
x1 = event.getX();
y1 = event.getY();
}
if(event.getAction() == MotionEvent.ACTION_UP) {
//当手指离开的时候
x2 = event.getX();
y2 = event.getY();
if(y1 - y2 > 50) {
Toast.makeText(MainActivity.this, "向上滑", Toast.LENGTH_SHORT).show();
} else if(y2 - y1 > 50) {
Toast.makeText(MainActivity.this, "向下滑", Toast.LENGTH_SHORT).show();
} else if(x1 - x2 > 50) {
Toast.makeText(MainActivity.this, "向左滑", Toast.LENGTH_SHORT).show();
} else if(x2 - x1 > 50) {
Toast.makeText(MainActivity.this, "向右滑", Toast.LENGTH_SHORT).show();
}
}
return super.onTouchEvent(event);
}
原文地址:http://blog.csdn.net/qiantujava/article/details/9903891