本文介绍了安卓:后才会onLongClick如何调用onTouch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形象,它可以左右移动和缩放捏的手势......所有这一切都在 onTouch做()。我想限制这一点,并使其移动(和可扩展性)只有在用户方面做的图像上的longclick。如何做到这一点?

I have an image, which can be moved around and scaled with pinch gesture.. All this is done inside onTouch(). I want to restrict this and make it movable(and scalable) only after the user has done a longclick on the image.. How do I do this?

推荐答案

注册一个的。如果长按是公认设置一个标志,真正的。

Register a LongCLickListener. If a long click is recognized set a flag to true.

在OnTouch方法允许缩放和移动仅当该标志被设置为true。之后,在移动和缩放再次设置标志设置为false。

In the OnTouch method allow scaling and moving only if the flag is set to true. After the moving and scaling set the flag to false again.

下面是一些伪code:

Here is some pseudocode:

public class MyActivity extends Activity {

   private boolean longClick = false;

   public boolean onTouch(View v, MotionEvent event) {
      if (longClick) {
         // do scaling and moving ...
         longClick = false;
      }
      return false;
   }

   public boolean onLongClick(View v) {
      longClick = true;
      return false;
   }
}

这篇关于安卓:后才会onLongClick如何调用onTouch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 22:07