android drag view smooth android drag view smooth android android

android drag view smooth


Try to use motionEvent.getRawX() and motionEvent.getRawY() instead of getY and getX


You need not to use LayoutParameters to drag. You can do it by just setting the X and Y coordinates of the view. You can read more on this here.

You can do something like this.

  @Override  public boolean onTouch(View view, MotionEvent event) {    switch (event.getActionMasked()) {      case MotionEvent.ACTION_DOWN:        dX = view.getX() - event.getRawX();        dY = view.getY() - event.getRawY();        break;      case MotionEvent.ACTION_MOVE:        view.setY(event.getRawY() + dY);        view.setX(event.getRawX() + dX);        break;      default:        return false;    }    return true;  }


The reason of non-smooth move is integer value of leftMargin and topMargin.
For smooth move position should be float.
This could help.