So, if i understood you correctly, you want to move an ImageView across the screen, drag it, and when you hit a certain spot with it you want to start another activity?
If so, you could try and use the code below...which let's you drag your imageview across the screen
Just add an onTouchListener to the imageView you're trying to slide (move/drag)
yourSlideImageViewObject.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
onSlideTouch(v, event);
return false;
}
});
Then add this code to handle the Touch events
public void onSlideTouch( View view, MotionEvent event )
{
//When the user pushes down on an ImageView
if ( event.getAction() == MotionEvent.ACTION_DOWN )
{
inDragMode = true; //Set a variable so we know we started draggin the imageView
//Set the selected ImageView X and Y exact position
selectedImageViewX = Math.abs((int)event.getRawX()-((ImageView)view).getLeft());
selectedImageViewY = Math.abs((int)event.getRawY()-((ImageView)view).getTop());
//Bring the imageView in front
((ImageView)view).bringToFront();
}
//When the user let's the ImageView go (raises finger)
if ( event.getAction() == MotionEvent.ACTION_UP )
{
inDragMode = false; //Reset the variable which let's us know we're not in drag mode anymore
}
//When the user keeps his finger on te screen and drags it (slides it)
if ( event.getAction() == MotionEvent.ACTION_MOVE )
{
//If we've started draggin the imageView
if ( inDragMode )
{
//Get the imageView object
ImageView slide = (ImageView)findViewById(R.id.slide);
//Get a parameters object (THIS EXAMPLE IS FOR A RELATIVE LAYOUT)
RelativeLayout.LayoutParams params = RelativeLayout.LayoutParams)slide.getLayoutParams();
//Change the position of the imageview accordingly
params.setMargins((int)event.getRawX()-selectedImageViewX, (int)event.getRawY()-selectedImageViewY, 0, 0);
//Set the new params
slide.setLayoutParams(params);
//If we hit a limit with our imageView position
if( slideImageView_position is inside an interval )
{
//Open another activity
Intent it = new Intent(Slide.this,NextActivity.class);
startActivity(it);
}
}
}
}
The above should drag your imageview accross the screen.
You can also implement in the MotionEvent.ACTION_MOVE event .... to limit the movement of the ImageView accross the screen. So check the new coordinates of your finger across the screen and check if they are out of bounds. If so, then do nothing. If they aren't out of bounds, then change the left and upper margins of the ImaveView.
Also, on the MotionEvent.ACTION_UP event, check to see if the left margin of the ImaveView is over a predefined limit (which means the user slided the imageView over you intended position). If so, you can continue doing whatever you want, which means starting an activity. OR, if you don't want to open the activity while the user is dragging, not only after he has removed his finger from the imageView, then just do that if () i've written under the MotionEvent.ACTION_MOVE event. Insert there the interval you want, so when the imageView is dragged inside that interval, the activity starts.
If you're confused, please ask :) It's very late here, and i'm tired, so i might have not explained it properly :D