public class MainActivity extends AppCompatActivity {
private ImageView imageView;
GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView= (ImageView) findViewById(R.id.imageView);
gestureDetector=new GestureDetector(this,new MyGestureListerner());
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
Log.i("info","华东了");
return false;
}
});
}
class MyGestureListerner extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.i("ges","华东了");
if (e1.getX()-e2.getX()>50){
Log.i("info","作画了");
Toast.makeText(MainActivity.this,"左滑了",Toast.LENGTH_SHORT).show();
}else if(e2.getX()-e1.getX()>50){
Log.i("info","优化了");
Toast.makeText(MainActivity.this,"右滑了",Toast.LENGTH_SHORT).show();
}
Log.i("ges","结束了");
return super.onFling(e1, e2, velocityX, velocityY);
}