I have layout with 5 different child views, Child views are relativelayout with number of child views inside it, and all are different too. Hence i am using scrollview as ro
Add this to your onCreate:
yourView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
drag(event, v);
return false;
}
});
And this to your Activity Class outside any methods.
public void drag(MotionEvent event, View v)
{
RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
{
params.topMargin = (int)event.getRawY() - (v.getHeight());
params.leftMargin = (int)event.getRawX() - (v.getWidth()/2);
v.setLayoutParams(params);
break;
}
case MotionEvent.ACTION_UP:
{
params.topMargin = (int)event.getRawY() - (v.getHeight());
params.leftMargin = (int)event.getRawX() - (v.getWidth()/2);
v.setLayoutParams(params);
break;
}
case MotionEvent.ACTION_DOWN:
{
v.setLayoutParams(params);
break;
}
}