title: How do I do an action when I move a view to right or left? Like a slide to lock button
body: <p>This is my layout. It has two views, I move one through the another.</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/time_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;RelativeLayout
          android:id="@+id/slide_layout"
          android:layout_width="match_parent"
          android:layout_height="50dp"
          android:layout_margin="20dp"
          android:layout_alignParentBottom="true" &gt;
  
          &lt;View
              android:id="@+id/slide_to_pause_backgound"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_centerHorizontal="true"
              android:background="#0000FF" /&gt;
  
          &lt;View
              android:id="@+id/slide_to_pause"
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_alignLeft="@+id/slide_to_pause_backgound"
              android:layout_alignParentBottom="true"
              android:background="#00FFFF" /&gt;
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is how I set in my activity class, the view to be moved:</p>
  
  <pre><code>slideView = ((View) findViewById(R.id.slide_to_pause));
  slideView.setOnTouchListener(this);   
  </code></pre>
  
  <p>And this is how I move the view:</p>
  
  <pre><code>@Override
  public boolean onTouch(View view, MotionEvent event) {
      final int X = (int) event.getRawX();
      final int Y = (int) event.getRawY();
  
      switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
  
      case MotionEvent.ACTION_DOWN:
          RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
          viewLeftMargin = X - lParams.leftMargin;
          viewTopMargin = lParams.topMargin;  
          viewBottomMargin = lParams.bottomMargin;
          viewRightMargin = X - lParams.rightMargin;
          break;
  
      case MotionEvent.ACTION_MOVE:
          RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
          layoutParams.rightMargin = X - viewRightMargin;
          layoutParams.leftMargin = X - viewLeftMargin;           
          layoutParams.topMargin = viewTopMargin;
          layoutParams.bottomMargin = viewBottomMargin;
          view.setLayoutParams(layoutParams);         
  
          break;
      }
      return true;
      }
  }
  </code></pre>
  
  <p>I want do an action when it goes to right and another when it goes to left.</p>
  
  <p>How can I do this? Thank you!</p>