我想在触摸监听器工作时使点击监听器停止

时间:2014-05-28 10:10:03

标签: android

我正在制作聊天头,我想在触摸监听器工作时点击监听器停止因为当触摸监听器正在工作时点击监听器正在工作,所以它打开窗口

我的代码:

单击侦听器

  chatHead.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

}

}

On Touch Listener

chatHead.setOnTouchListener(new View.OnTouchListener() {






              private int initialX;
              private int initialY;
              private float initialTouchX;
              private float initialTouchY;

              @Override public boolean onTouch(View v, MotionEvent event) {





                  if (on.equals("true"))
                  {
                      params.x = 0;
                        params.y = 0;


                        windowManager.updateViewLayout(chatHead, params); 
                  }



                switch (event.getAction()) {
                  case MotionEvent.ACTION_DOWN:
                    initialX = params.x;
                   initialY = params.y;
                    initialTouchX = event.getRawX();
                   initialTouchY = event.getRawY();
                     // Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();

                    return false;

                  case MotionEvent.ACTION_UP:
                    //  Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
                    return false;
                  case MotionEvent.ACTION_MOVE:
                    params.x = initialX + (int) (event.getRawX() - initialTouchX);
                   params.y = initialY + (int) (event.getRawY() - initialTouchY);

                    windowManager.updateViewLayout(chatHead, params);



                    return false;


                }
                return false;
              }
        });
      }

编辑:

你知道Facebook的信使聊天头当你移动聊天头它随你移动时当你点击它打开它我正在聊聊头像Facebook聊天头但是当我移动它移动但它也会在移动时打开我想点击像Facebook上的点击触摸,所以当它移动我永远不会打开

5 个答案:

答案 0 :(得分:0)

您是否尝试过setOnClickListener(null);

答案 1 :(得分:0)

true消费此活动时,您是否尝试在onTouch()内回复OnTouchListener

更新: 据我了解您的代码所做的事情,我认为在case MotionEvent.ACTION_UP时,您应该返回true

答案 2 :(得分:0)

在ChatHead类中创建一个实例成员,boolean bFireOnClick;当你的应用程序处理onTouch时,你可以做到

bFireOnClick = false;

和OnClick侦听器

if(bFireOnClick){
 bFireOnClick = false;
 return; 

}

答案 3 :(得分:0)

当您在false内返回OnTouchListener时,它将允许OnClickListener处理点击次数。如果您在true内返回OnTouchListener,则不会同时触发其他事件。因此,如果您不想同时处理OnTouchListenertrue个事件,请在click内尝试返回touch

chatHead.setOnTouchListener(new View.OnTouchListener() {

              private int initialX;
              private int initialY;
              private float initialTouchX;
              private float initialTouchY;

              @Override public boolean onTouch(View v, MotionEvent event) {

                  if (on.equals("true"))
                  {
                      params.x = 0;
                        params.y = 0;


                        windowManager.updateViewLayout(chatHead, params); 
                  }

                switch (event.getAction()) {
                  case MotionEvent.ACTION_DOWN:
                    initialX = params.x;
                   initialY = params.y;
                    initialTouchX = event.getRawX();
                   initialTouchY = event.getRawY();
                     // Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();

                    return true;

                  case MotionEvent.ACTION_UP:
                    //  Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
                    return true;
                  case MotionEvent.ACTION_MOVE:
                    params.x = initialX + (int) (event.getRawX() - initialTouchX);
                   params.y = initialY + (int) (event.getRawY() - initialTouchY);

                    windowManager.updateViewLayout(chatHead, params);

                   return true;
                    }
                return true;
              }
        });
      }

答案 4 :(得分:0)

答案是

int open ;



Image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if ( open < 10)
{
do it
}
}
}











case MotionEvent.ACTION_MOVE:

open++;

return false;




switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:

open=0;
return false;