GestureDetector怎么样式不起作用怎么解决

android使用gesturedetector手势识别示例分享
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了android使用手势识别的方法,介绍了单击触摸屏触发的事件和双击事件的使用等方法,大家参考使用吧
代码如下:public class MyGestureLintener extends SimpleOnGestureListener {private Cpublic MyGestureLintener(Context context) {&&& super();&&& this.context =}
// 单击,触摸屏按下时立刻触发/*@Overridepublic boolean onDown(MotionEvent e) {&&& // TODO Auto-generated method stub&&& Toast.makeText(context, "Down " + e.getAction(), Toast.LENGTH_SHORT)&&&&&&& .show();&&&}*/// 双击,手指在触摸屏上迅速点击第二下时触发@Overridepublic boolean onDoubleTap(MotionEvent e) {&&& // TODO Auto-generated method stub&&& return super.onDoubleTap(e);}
// 双击的按下跟抬起各触发一次@Overridepublic boolean onDoubleTapEvent(MotionEvent e) {&&& // TODO Auto-generated method stub&&& return super.onDoubleTapEvent(e);}
// 滑动,触摸屏按下后快速移动并抬起,会先触发滚动手势,跟着触发一个滑动手势@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,&&&&&&& float velocityY) {&&& // TODO Auto-generated method stub&&& return super.onFling(e1, e2, velocityX, velocityY);}
// 长按,触摸屏按下后既不抬起也不移动,过一段时间后触发@Overridepublic void onLongPress(MotionEvent e) {&&& // TODO Auto-generated method stub&&& Toast.makeText(context, "LONG " + e.getAction(), Toast.LENGTH_SHORT)&&&&&&&&&&& .show();}
// 滚动,触摸屏按下后移动@Overridepublic boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,&&&&&&& float distanceY) {&&& Toast.makeText(context, "onScroll " + e2.getAction(), Toast.LENGTH_SHORT)&&& .show();&&&}
// 短按,触摸屏按下后片刻后抬起,会触发这个手势,如果迅速抬起则不会@Overridepublic void onShowPress(MotionEvent e) {&&& // TODO Auto-generated method stub&&& Toast.makeText(context, "Show " + e.getAction(), Toast.LENGTH_SHORT)&&&&&&&&&&& .show();
// 单击确认,即很快的按下并抬起,但并不连续点击第二下/*@Overridepublic boolean onSingleTapConfirmed(MotionEvent e) {&&& // TODO Auto-generated method stub&&& Toast.makeText(context, "onSingleTapConfirmed " + e.getAction(), Toast.LENGTH_SHORT)&&& .show();&&&}*/
// 抬起,手指离开触摸屏时触发(长按、滚动、滑动时,不会触发这个手势)/*@Overridepublic boolean onSingleTapUp(MotionEvent e) {&&& // TODO Auto-generated method stub
&&& Toast.makeText(context, "onSingleTapUp " + e.getAction(), Toast.LENGTH_SHORT)&&& .show();&&&}*/public class MainActivity extends Activity {private GestureDetector mGestureD//手势对象private MyGestureLintener myGestureL//手势监听的接口对象
@Overrideprotected void onCreate(Bundle savedInstanceState) {&&& super.onCreate(savedInstanceState);&&& setContentView(R.layout.activity_main);&&& myGestureLintener = new MyGestureLintener(this);
&&& //手势对象的构造方法&&& mGestureDetector = new GestureDetector(this,&&&&&&&&&&& myGestureLintener);}
/**GestureDetector类的onTouchEvent方法用来辨别不同的手势*/@Overridepublic boolean onTouchEvent(MotionEvent event) {&&& boolean b =&&& int i = event.getAction();&&& int j = MotionEvent.ACTION_MOVE;&&& System.out.println(i+"&-----------------&"+j);&&& b = mGestureDetector.onTouchEvent(event);&&& if (b) {&&&&&&& Intent in = new Intent();&&&&&&& in.setClass(this, testActivity.class);&&&&&&& startActivity(in);&&& }&&&
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {&&& // I this adds items to the action bar if it is present.&&& getMenuInflater().inflate(R.menu.main, menu);&&&}}
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具2011年2月 移动平台大版内专家分月排行榜第三2011年1月 移动平台大版内专家分月排行榜第三2010年10月 移动平台大版内专家分月排行榜第三
2011年2月 移动平台大版内专家分月排行榜第三2011年1月 移动平台大版内专家分月排行榜第三2010年10月 移动平台大版内专家分月排行榜第三
2011年2月 移动平台大版内专家分月排行榜第三2011年1月 移动平台大版内专家分月排行榜第三2010年10月 移动平台大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。博客分类:
在做OnGestureListener手势滑动界面的时候,会遇到这样的问题,就是当界面中含有ListView的时候,OnGestureListener的界面滑动就被ListView拦截并消费掉了。
为了解决这个问题需要重写ListView的OnTouchListener接口:
ListView listView=(ListView)findViewById(R.id.listViewBeside);
listView.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
leftPanel.getGestureDetector().onTouchEvent(event);//需要这样写!
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView&?& parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Log.i("tag", "position=="+position);
因为我的手势是定义在leftPanel这个View中的,所以是leftPanel.getGestureDetector().onTouchEvent(event);。如果你的手势是写在Activity中的,那么就是mGestureDetector.onTouchEvent(event);
这样既能保证在ListView上实现拖动,又能保证ListView上的Item Click.
gundumw100
浏览: 4196266 次
来自: 上海
本地lua脚本终于执行成功了,虽然不是通过redis
大神://处理返回的接收状态
这个好像没有监听到
拦截部分地址,怎么写的for(int i=0;i&lis ...
Android控件之带清空按钮(功能)的AutoComplet ...
希望有表例子更好。。。,不过也看明白了。
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'本帖子已过去太久远了,不再提供回复功能。博客分类:
仅作摘要,便于回顾。
我们知道Android中可以为组件设置onTouchListener(),来监听上面的onTouch()事件,但是onTouch()只能处理比较简单的事件,所以Android中有一个封装好的手势监听类GestureDetector,可以为该类配置相应的监听接口,如:SimpleOnGestureListener对象。问题的关键是,我们可以为自己的组件设置onTouchListener(),并在其中的onTouch()方法中将MotionEvent参数传递给GestureDetector.onTouchEvent(),即调用GestureDetector的onTouchEvent方法。
另外这里我还遇到了一个问题,就是GestureDetector只能放在某个具体的组件中,比如:要监听一个ImageView上手势事件,需要将GestureDetector对象放到这个ImageView类中,而不是在Activity中调用ImageView.onTouchListener()中将MotionEvent传递给GestureDetector对象。否则只会触发ImageView的DOWN,SLOW_PRESS,LONG_PRESS事件,而没有触发诸如:SCROLL,FLING等事件。
浏览: 45219 次
新建一个标记FLAG,将其初始化为ture,在需要退出时,将F ...
怎么一直运行? 在哪里退出呢?
while(ture)
{
} ...
博主,你好,我最近也在做学校的课题。是关于短信安全的,用维吉尼 ...
我也报了这个错. 直接错误是没错. Android调试确实不太 ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 圣人崩坏对谁不起作用 的文章

 

随机推荐