GestureDetector--手势识别初体验(一)
来源:互联网 发布:德国读研一年费用知乎 编辑:程序博客网 时间:2024/05/15 10:30
双击爆炸;右向左滑动←;左向右滑动→;
MainActivity.class
package com.superxingyun.gestruedetectordemo;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.GestureDetector;import android.view.GestureDetector.SimpleOnGestureListener;import android.view.MotionEvent;import android.view.View;import android.widget.ImageView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { ImageView img; GestureDetector gestureDetector; class MyGestureListen extends SimpleOnGestureListener{ @Override//滑动事件 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > 50){ Toast.makeText(MainActivity.this, "←←←←←←←←←←", Toast.LENGTH_SHORT).show(); }else if (e2.getX() - e1.getX() >50){ Toast.makeText(MainActivity.this, "→→→→→→→→→→", Toast.LENGTH_SHORT).show(); } return super.onFling(e1, e2, velocityX, velocityY); } /* @Override//单击事件 public boolean onDown(MotionEvent e) { Toast.makeText(MainActivity.this, "...........", Toast.LENGTH_SHORT).show(); return super.onDown(e); }*/ @Override//双击事件 public boolean onDoubleTap(MotionEvent e) { Toast.makeText(MainActivity.this, "BOOM", Toast.LENGTH_SHORT).show(); return super.onDoubleTap(e); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gestureDetector = new GestureDetector(MainActivity.this, new MyGestureListen()); img = (ImageView) findViewById(R.id.img); img.setOnTouchListener(new View.OnTouchListener() { @Override//可以捕获到触摸屏幕发生的Event事件 public boolean onTouch(View vew, MotionEvent motionEvent) { gestureDetector.onTouchEvent(motionEvent); return true; } }); }}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.superxingyun.gestruedetectordemo.MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@mipmap/i" android:layout_centerVertical="true" android:id="@+id/img" /></RelativeLayout>
0 0
- GestureDetector--手势识别初体验(一)
- (转) Android GestureDetector手势识别类
- Android GestureDetector手势识别
- 手势识别类 GestureDetector
- 多点手势识别GestureDetector
- GestureDetector手势识别
- GestureDetector android 手势识别
- GestureDetector(手势识别)
- Android 手势识别--GestureDetector
- Android-----手势识别GestureDetector
- GestureDetector 手势识别
- GestureDetector 手势识别器
- GestureDetector手势识别--笔记
- GestureDetector手势识别浅析
- 手势识别--GestureDetector
- GestureDetector 手势识别
- GestureDetector 手势滑动识别
- GestureDetector识别手势滑动
- Web 推送
- error LNK1104: 无法打开文件“acedapi.lib”
- C/C++笔试 -----void*
- 《java编程思想》第三章:操作符
- 《大数据时代(BIG DATA)》
- GestureDetector--手势识别初体验(一)
- xss(cookie劫持)
- android VideoView视频引导页
- Parajumpers Herren scene enjoy cool
- 替换文件中某个字符串并写入新内容(Java代码实现)
- iOS常用工具正则表达式判断手机邮编身份证快递单手机中间加※
- MySQL递归查询树状表的子节点、父节点具体实现
- 日常潜水-20160927-安装PHP-DOMDocument模块
- 不使用notifyDataSetChanged更新ListView