But you are doing wrong here. You have mentioned that you need to touch on RelativeLayout but here you are using
layout_own_container = new LinearLayout(this);
means linear layout. So you have to change and find id for your Relative Layout on onCreate() method.
RelativeLayout rel = (RelativeLayout) findViewById(R.id.relative_iown_top);
rel.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "WTF", Toast.LENGTH_SHORT).show();
final int X = (int) event.getRawX();
float dest = 0;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = X - lParams.leftMargin;
break;
case MotionEvent.ACTION_UP:
switch (view.getId()){
case 1:
dest = bIOwn.getWidth() + bIWish.getWidth();
break;
}
ObjectAnimator animation2 = ObjectAnimator.ofFloat(view, "x", dest);
animation2.setDuration(100);
animation2.start();
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
float width = layout_own_top.getWidth() - dest;
if (view.getWidth() != width){
RelativeLayout.LayoutParams layoutParams_move = (RelativeLayout.LayoutParams) view.getLayoutParams();
layoutParams_move.leftMargin = X - _xDelta;
layoutParams_move.rightMargin = -(layout_own_top.getWidth() + 200);
view.setLayoutParams(layoutParams_move);
}
break;
}
layout_own_top.invalidate();
return true;
}
});