当前位置:网站首页>Gesturedetector (gesture recognition)
Gesturedetector (gesture recognition)
2022-07-27 19:52:00 【Ashurol】
android Provide a for gesture recognition GestureDetector, When creating a GestureDetector.OnGestureListener Listen to the instance
by Activity Or component specific TouchEvent Bind listener
by Activity Bind instance
public class MainActivity extends Activity implements OnGestureListener{
GestureDetector detector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
detector=new GestureDetector(this, this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return detector.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onDown", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onFling", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onLongPress", Toast.LENGTH_SHORT).show();
}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onScroll", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onShowPress", Toast.LENGTH_SHORT).show();
}
@Override
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onSingleTapUp", Toast.LENGTH_SHORT).show();
return false;
}
}
Bind instances for specific components
public class MainActivity extends ActionBarActivity {
ImageView image;
GestureDetector detector;
class myOnGestureListener extends SimpleOnGestureListener{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
//
if(e1.getX()-e2.getX()>50)
{
Toast.makeText(MainActivity.this, " Fingers to the left ", Toast.LENGTH_SHORT).show();
}else if(e2.getX()-e1.getX()>50)
{
Toast.makeText(MainActivity.this, " Fingers to the right ", Toast.LENGTH_SHORT).show();
}
return super.onFling(e1, e2, velocityX, velocityY);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView) findViewById(R.id.image);
detector=new GestureDetector(new myOnGestureListener());
image.setOnTouchListener(new OnTouchListener() {
@Override
// It can be captured that touch is happening Event event
public boolean onTouch(View arg0, MotionEvent event) {
// TODO Auto-generated method stub
detector.onTouchEvent(event);//detector Put the event event Forward to OnGestureListener Handle
return true;
}
});
}
}
边栏推荐
- 坚持软硬一体化,一恒科发力智能化教育机器人市场
- 二叉搜索树
- Fabric上搭建Hyperledger caliper进行性能测试
- View pagoda PHP extension directory
- Embedded C language pointer alias
- 5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress
- 强化学习介绍
- 【深度学习基础知识 - 38】L1正则化和L2正则化的区别
- [basic knowledge of deep learning - 47] Bayesian networks and naive Bayes
- IDEA:解决代码没有提示问题
猜你喜欢

SharePreference(存储)

GridView(实现表格显示图标)

Detailed explanation of the underlying data structure of redis

ToggleButton(按钮开关)

5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress

VS2017#include 'xxx.h'

ArrayAdapter(数组适配器)与SimpleAdapter(简单适配器)

Map和Set

二叉搜索树

Come to sword finger offer 03. Repeated numbers in the array
随机推荐
IDEA:解决代码没有提示问题
Surpass Huawei? Ericsson has won more than 75 5g commercial contracts
下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增
JS 寻找所有节点sibling childNodes children
AutoCompleteTextView(输入框预匹配)
rxbinding
I want to consult. Our maxcompute spark program needs to access redis, development environment and production environment redis
SQLServer 2008中事务日志已满问题处理
英特尔推出全球最小的高分辨率激光雷达,售价仅349美元
【深度学习基础知识 - 50】PCA降维 主成成分分析
【华为云Stack】【大架光临】第13期:管理区解耦架构见过吗?帮政企客户搞定大难题
Publish your own NPM component library
Uncover the mystery of Qualcomm ultrasonic fingerprint being "cracked by film"
File operation protection
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte
What's new in helix QAC 2022.2, the ace code static testing tool (2)
An unknown fastcgi error occurred in IIS: 0x80070005
王牌代码静态测试工具Helix QAC 2022.2 中的新增功能(1)
Use of jvisualvm
英特尔发布Horse Ridge芯片:22nm工艺,能够控制多个量子位