package yxqz.com;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.GestureDetector.OnGestureListener;
import android.view.SurfaceHolder.Callback;
import android.widget.Toast;
public class MainActivity extends Activity implements OnGestureListener{
private static final int FLING_MIN_DISTANCE = 100;
private GestureDetector gd; // 手势
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gd=new GestureDetector(this); //创建手势监听对象
}
@Override
public boolean onTouchEvent(MotionEvent event) {
gd.onTouchEvent(event); //通知手势识别方法
return super.onTouchEvent(event);
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE) {
Toast.makeText(this, "左滑动"+(e1.getX() - e2.getX()), Toast.LENGTH_SHORT).show();
return true;
}
if (e1.getX() - e2.getX() < -FLING_MIN_DISTANCE) {
Toast.makeText(this, "右滑动"+(e1.getX() - e2.getX()), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
public boolean onDown(MotionEvent e) {
return false;
}
public void onLongPress(MotionEvent e) {
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
public void onShowPress(MotionEvent e) {
}
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}