title: How to make the TextView drag in LinearLayout smooth, in android?
body: <p>I have a situation which I am not able to fix, hopefully I will get some advises from you.</p>
  
  <p>The situation is simple: I have a LinearLayout in which I have a TextView with multiple lines of text. The user is able to drag the TextView around until he finds a position he likes. What is really important is that the TextView can be partially out of the LinearLayout (it will appear cut).</p>
  
  <p>Here are some code samples:</p>
  
  <pre><code> &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="top|center_horizontal"
          android:clipChildren="false"
          android:gravity="center_horizontal|center_vertical"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:textColor="@color/text_color"
              android:textSize="16sp" /&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>As you can see the LinearLayout has clipChildren = false to allow cutoff of text.
  For the textview I set a touch listener</p>
  
  <pre><code>txt.setOnTouchListener(new View.OnTouchListener() {
              int initialX = 0;
              int initialY = 0;
  
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  switch (event.getActionMasked()) {
                  case MotionEvent.ACTION_DOWN:
                      initialX = (int) event.getX();
                      initialY = (int) event.getY();
                      break;
                  case MotionEvent.ACTION_MOVE:
                              int currentX = (int) event.getX();
                              int currentY = (int) event.getY();
                              LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) txt.getLayoutParams();
  
                              int left = lp.leftMargin + (currentX - initialX);
                              int top = lp.topMargin + (currentY - initialY);
                              int right = lp.rightMargin - (currentX - initialX);
                              int bottom = lp.bottomMargin - (currentY - initialY);
  
                              lp.rightMargin = right;
                              lp.leftMargin = left;
                              lp.bottomMargin = bottom;
                              lp.topMargin = top;
  
                              txt.setLayoutParams(lp);
                      break;
                  default:
                      break;
                  }
                  return true;
              }
          });
  </code></pre>
  
  <p>And here is my problem: As you can see I've set all the layout parameters (right, left, bottom, top margins). Why is that ?</p>
  
  <p>1) If I use only left/top the drag is smooth enought but text get's wrapped at the right border instead of getting cut. Probably due to right 0 margin value.</p>
  
  <p>2) If I use all margins, the text gets cut as I want, but the movement is not smooth, it just jumps around for a few pixels.</p>
  
  <p>How can I fix this ?</p>