安卓:后才会onLongClick如何调用onTouch?才会、onLongClick、onTouch

由网友(陷阱里的王子)分享简介:我有一个形象,它可以左右移动和缩放捏的手势......所有这一切都在 onTouch做()。我想限制这一点,并使其移动(和可扩展性)只有在用户方面做的图像上的longclick。如何做到这一点?I have an image, which can be moved around and scaled with pin...

我有一个形象,它可以左右移动和缩放捏的手势......所有这一切都在 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?

推荐答案

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

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;
   }
}
阅读全文

相关推荐

最新文章