Android onGestureListener和onTouchListner

Android onGestureListener和onTouchListner,第1张

概述我在android工作.我有一些功能可以通过以下方法完成:–1.MotionEvent.ACTION_DOWN2.MotionEvent.ACTION_UP3.MotionEvent.ACTION_MOVE我也想对那张图片做一个fling().对于上面的要求我在我的应用程序中实现了onGestureListener和onTouchListener,但这些都无法正常工作.

我在android工作.我有一些功能可以通过以下方法完成: –

1. MotionEvent.ACTION_DOWN2. MotionEvent.ACTION_UP3. MotionEvent.ACTION_MOVE

我也想对那张图片做一个fling().

对于上面的要求我在我的应用程序中实现了onGestureListener和ontouchListener,但这些都无法正常工作. ontouchListener正在运行,但onGestureListener无法正常工作.当我删除ontouchListner代码然后onGestureListener正常工作.

所以请建议我该怎么做.我想在我的应用程序中实现这四种方法.

1. MotionEvent.ACTION_DOWN2. MotionEvent.ACTION_UP3. MotionEvent.ACTION_MOVE4. onFling

解决方法:

您可以通过从活动中实现OnGestureListener来覆盖以下方法来实现此目的

// For touch public boolean onSingleTapUp(MotionEvent event) { return false; }// For Fling public boolean onFling(MotionEvent e1, MotionEvent e2, float veLocityX,        float veLocityY) {    return false;}

希望这可以帮助.

编辑1:详细说明:

1 GT;从您的活动中实现OnGestureListener

public class MyActivity implements OnGestureListener

2 – ;创建一个GestureDetector实例:

private GestureDetector gestureScanner;

在onCreate:

// AvoID a deprecated constructor // (http://developer.androID.com/reference/androID/vIEw/GestureDetector.HTML)gestureScanner = new GestureDetector(this, this);

3 GT;覆盖以下方法:

@OverrIDepublic boolean ontouchEvent(MotionEvent event) {    return gestureScanner.ontouchEvent(event);}@OverrIDepublic boolean onFling(MotionEvent e1, MotionEvent e2, float veLocityX,        float veLocityY) {    /* on scroll to the next page in story */    if (e2.getX() - e1.getX() > SWIPE_MIN_disTANCE            && Math.abs(veLocityX) > SWIPE_THRESHolD_VELociTY) {        // ...    }    /* on scroll to the prevIoUs page in story */    else if (e1.getX() - e2.getX() > SWIPE_MIN_disTANCE            && Math.abs(veLocityX) > SWIPE_THRESHolD_VELociTY) {        // ...    }    return false;}@OverrIDepublic boolean onSingleTapUp(MotionEvent event) {    return false;}

编辑2:处理移动
覆盖onScroll方法看一下细节here

总结

以上是内存溢出为你收集整理的Android onGestureListener和onTouchListner全部内容,希望文章能够帮你解决Android onGestureListener和onTouchListner所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1112846.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存