title: How to move a view in only three directions
body: <p>I am using onTouch Listener to move the view in 2 directions left and right , Now I want to move my view in Upwards also , it should move only in a straight line like x positive axis and negative , and also y positive axis only . I am doing the following code to implement this functionality .</p>
  
  <p>I want my view should move like this :</p>
  
  <pre><code>           up
              ^
              |
    left&lt;---- | ----&gt;right
  
  public boolean onTouch(View view, MotionEvent event) {
  
      switch (event.getAction()) {
  
          case MotionEvent.ACTION_DOWN:
  
              dX = view.getX() - event.getRawX();
              dY = view.getY() - event.getRawY();
              break;
  
          case MotionEvent.ACTION_MOVE:
  
              view.animate()
                      .x(event.getRawX() + dX)
                      .y(event.getRawY() + dY)
                      .setDuration(0)
                      .start();
              break;
          default:
              return false;
      }
      return true;
  }
  </code></pre>