title: drag a layout in android like in facebook for android app
body: <p>i tried to implement Facebook like dragging by changing margins of a layout ,however those always leave behind trails even if i call invalidate on the view</p>
  
  <p>Facebook for android /ios does it ,i wonder how they did it ,everywhere i see only images being dragged and dropped</p>
  
  <p>i m trying to implement something <a href="http://i.stack.imgur.com/Gyhah.png" rel="nofollow">like this</a> however it leaves behind trails in my app</p>
  
  <pre><code>package com.example.dragdemo;
  
  @SuppressLint({ "NewApi", "ParserError", "ParserError" })
  public class MainActivity extends Activity {
  
  TextView x;
  TouchExampleView tex;
  Context ctx=MainActivity.this;
  
  private float mPosX=0;
  private float mPosY=0;
  
  private float mLastTouchX;
  private float mLastTouchY;
  
  LinearLayout redLinear;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      tex=new TouchExampleView(ctx);
  
      redLinear=(LinearLayout)findViewById(R.id.newLinear);
      redLinear.setOnTouchListener(new OnTouchListener() {
  
          public boolean onTouch(View v, MotionEvent event) {
  
              //Log.e("action is ", event.getAction()+"");
  
              if(event.getAction()==MotionEvent.ACTION_MOVE)
              {
                  //Toast.makeText(ctx, "comes in move", Toast.LENGTH_SHORT).show();
  
                  if(((mPosX-(int) event.getX())&gt;2002)||((mPosX-(int) event.getX())&lt;2002)){
  
                      mPosX=(int) event.getX();
                      RelativeLayout.LayoutParams rl=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                      //rl.addRule(RelativeLayout., anchor)
  
                      rl.setMargins((int) event.getX(), 0, 0, 0);
  
                      redLinear.setLayoutParams(rl);
                      redLinear.invalidate();
  
                  }
              }
              return true;
          }
      });
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
  }
  }
  </code></pre>