title: Android move view on touch event
body: <p>I would like to move two different views into my layout, so that an user can display it like his wishes.</p>
  
  <p>So far I've made the following code to handle the touch event:</p>
  
  <pre><code>this.viewEvent.setOnTouchListener(new OnTouchListener() {
      @Override
      public boolean onTouch(View view, MotionEvent event)
      {           
          final int y = (int) event.getRawY();
  
          RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();
          switch (event.getAction() &amp; MotionEvent.ACTION_MASK)
          {
              case MotionEvent.ACTION_DOWN:
                  element.setEventY(y - params.topMargin);
                  break;
  
              case MotionEvent.ACTION_UP:
                  viewGroup.invalidate();
                  break;
  
              case MotionEvent.ACTION_POINTER_DOWN:
              case MotionEvent.ACTION_POINTER_UP:
                  break;
  
              case MotionEvent.ACTION_MOVE:
                  params.topMargin = y - element.getEventY();
                  params.bottomMargin = screenHeight - view.getHeight() - params.topMargin;
  
                  // Avoid out of screen
                  if (params.topMargin &lt; 0) return true;
  
                  // Apply changes
                  view.setLayoutParams(params);
                  break;
          }
  
          return true;
      }
  });
  </code></pre>
  
  <p><code>element</code> is an instance of a custom object to handle the position.
  <code>screenHeight</code> is the screen height given by the <code>Display</code> class.</p>
  
  <p>I'm able to move the element but it's blinking when I touch it and once I put my finger up, the view just disapear. I can't even retrieve it, it's just out of the screen.</p>
  
  <p>Did I make something wrong ?</p>
  
  <p>Thanks for your help</p>