title: How to create a movable and clickable button in android
body: <p>I'm new to Xamarin Android and currently working on a floating action button, I implemented <strong>View.IOnTouchListener</strong> and normal button click event (faButton.Click += floatButtonPressed;) to carry out my actions. But for the <strong>case MotionEventActions.Move</strong>, it doesn't work as I wanted. Moving left and right it works fine but for top and bottom it will move downwards a little bit whenever I start moving it. Besides, when I move the button to screen border it will be able to exceed the screen. Hence, I tried detect screen size and restrict it but it still not good enough, is there any other available solution or settings?</p>
  
  <pre><code>public bool OnTouch(View v, MotionEvent e)
      {
          switch (e.Action)
          {
              case MotionEventActions.Down:
                  oldXvalue = e.GetX();
                  oldYvalue = e.GetY();
  
                  if (oldXvalue == e.GetX() &amp;&amp; oldYvalue == e.GetY())
                  {
                      return false;
                  }
  
                  break;
  
              case MotionEventActions.Up:
  
                  if (oldXvalue == e.GetX() &amp;&amp; oldYvalue == e.GetY())
                  {
                      return false;
                  }                   
                  break;
  
              case MotionEventActions.Move:
                  var xleft = (int)(e.RawX - oldXvalue);
                  var xright = xleft + v.Width;
                  var ytop = (int)(e.RawY - oldYvalue);
                  var ybtm = (ytop + v.Height);
                  if (xleft + v.Width &gt;= intWidth)
                  {
                      break;
                  }
                  if (xleft &lt;= 0)
                  {
                      break;
                  }
  
                  if (ytop + v.Height &gt;= intHeight)
                  {
                      break;
                  }
                  if (ytop &lt;= 0)
                  {
                      break;
                  }
                  v.Layout(xleft, ytop, xright, ybtm);
                  break;
          }
          return true;
      }
  </code></pre>