Android 多点触控和双击协同工作以实现图像视图

发布于 2024-10-10 14:31:46 字数 326 浏览 3 评论 0原文

你好 我在 LinearLayout(垂直方向)中有两个图像视图。我正在为两个 Imageview 设置 setOnTouchListener 。 这样我就能够观察多点触摸缩放以及 ImageView 的所有拖动。 当我尝试实现 OnDoubletapListener 时,问题就出现了。 OnDoubleTapListener 仅在不使用 setOnTouchListener 的情况下工作。

但是,如果我评论 setOnTouchListner 那么我就可以执行双击。

这两个功能不能同时工作吗???

如果您愿意,我也可以提供源代码.. 请帮助

Ankit Verma

Hi
I have two imageviews in a LinearLayout(Vertical orientation). I am setting setOnTouchListener for both the Imageviews.
This way i am able to observe the Multi touch zoom as well as all the dragging of the ImageViews.
The problem comes when i try to implement OnDoubletapListener.
OnDoubleTapListener works only without the use of setOnTouchListener.

However if i comment the setOnTouchListner then i am able to perform Double Tap..

Can't the two feartures work simultaneously?????

If You want i can provide the source code as well..
Pl Help

Ankit Verma

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断爱 2024-10-17 14:31:46

我也遇到过同样类型的问题....我用这种方式解决...

如果你使用 android mutitouch 控制器 http://code.google.com/p/android-multitouch-controller/ 用于多点触控

和 GestureDetector http://www.41post.com/4194/programming/android-detecting-double-tap-events 用于双击

而不是

更新此MultiTouchController.java 中的步骤

-->导入

  import android.view.GestureDetector.OnDoubleTapListener;

  import android.view.GestureDetector.OnGestureListener;

-->实施

 public class MultiTouchController<T> implements OnGestureListener{

-->

public MultiTouchController(MultiTouchObjectCanvas<T> objectCanvas2, boolean handleSingleTouchEvents) {

           //....

    gd = new GestureDetector(this);

    // set the on Double tap listener
    gd.setOnDoubleTapListener(new OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // set text color to green
            Log.d("CLICK", "double taped");



            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // if the second tap hadn't been released and it's being moved
            if (e.getAction() == MotionEvent.ACTION_MOVE) {
                Log.d("CLICK", "double tap event ACTION_MOVE");
            } else if (e.getAction() == MotionEvent.ACTION_UP)// user
                                                                // released
                                                                // the
                                                                // screen
            {
                Log.d("CLICK", "double tap event ACTION_UP");
            }
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // set text color to red
            Log.d("CLICK", "single taped");

            return true;
        }
    });

-->在 onTouch(MotionEvent event) 处将触摸事件设置为 gd

   public boolean onTouchEvent(MotionEvent event) {

    gd.onTouchEvent(event);

    try {

               //.....

不要在任何其他文件中进行更改。

现在测试...希望你解决问题...必须回复...

I had also face that same type problem....I solve with this way...

If You using android mutitouch controller http://code.google.com/p/android-multitouch-controller/ for multitouch

and GestureDetector http://www.41post.com/4194/programming/android-detecting-double-tap-events for double tap

than

update this steps in MultiTouchController.java

--> import

  import android.view.GestureDetector.OnDoubleTapListener;

  import android.view.GestureDetector.OnGestureListener;

--> implement

 public class MultiTouchController<T> implements OnGestureListener{

-->

public MultiTouchController(MultiTouchObjectCanvas<T> objectCanvas2, boolean handleSingleTouchEvents) {

           //....

    gd = new GestureDetector(this);

    // set the on Double tap listener
    gd.setOnDoubleTapListener(new OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // set text color to green
            Log.d("CLICK", "double taped");



            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // if the second tap hadn't been released and it's being moved
            if (e.getAction() == MotionEvent.ACTION_MOVE) {
                Log.d("CLICK", "double tap event ACTION_MOVE");
            } else if (e.getAction() == MotionEvent.ACTION_UP)// user
                                                                // released
                                                                // the
                                                                // screen
            {
                Log.d("CLICK", "double tap event ACTION_UP");
            }
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // set text color to red
            Log.d("CLICK", "single taped");

            return true;
        }
    });

--> set touch event to gd at onTouch(MotionEvent event)

   public boolean onTouchEvent(MotionEvent event) {

    gd.onTouchEvent(event);

    try {

               //.....

Don't change in any other files.

Now test...Hope you solved problem...must reply...

随波逐流 2024-10-17 14:31:46

嘿,我不知道你是否仍然遇到同样的问题,但我找到了一种方法来解决它。事实上,我只是为多点触摸事件实现了 OnTouchListner,并测量了两次调用 ACTION_DOWN 之间的时间。如果该时间小于某个值,我认为这是双击,并相应地执行操作。希望有帮助。如果您找到了同时实现 OnTouchListner 和 GestureDetector.OnDoubleTapListener 的方法,请告诉我!

Hey I don't know if you are still stuck with the same problem but I found a way to get around it. In fact, I just implement the OnTouchListner for the multitouch events and I measure the time between two calls to ACTION_DOWN. If that time is smaller than a certain value, I consider that this was a double touch and I perform the actions consequently. Hope that helps. If you found a way to implement both the OnTouchListner and the GestureDetector.OnDoubleTapListener please let me know!

花伊自在美 2024-10-17 14:31:46

请检查下面的链接,可能对您有帮助..implements GestureDetector
http://android-journey.blogspot.com/2010/01/android -gestures.html

GestureDetector.OnDoubleTapListener
{用于在双击或确认单击发生时发出通知的侦听器。 }

Please check below link , may be helpful to you ..implements GestureDetector
http://android-journey.blogspot.com/2010/01/android-gestures.html

GestureDetector.OnDoubleTapListener
{The listener that is used to notify when a double-tap or a confirmed single-tap occur. }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文