dragging a image in boundary

view full story

http://stackoverflow.com – I want that image only be dragged in its parent view. when user tries to drag it outside the view it will return its original position. basically i'm implementing android unlock type feature. please help me out. Its my main class. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.myimage1).setOnTouchListener(new MyTouchListener()); findViewById(R.id.topleft).setOnDragListener(new MyDragListener()); } private final class My (HowTos)