I'm using an ImageView to display an image twice as big as the screen.
I'm trying to make it scroll and snap like the home screen does, where
the user can drag the view left and right to see the two different
sides of the image. Can anyone at least point me in the right
direction on what method to be using.
I'm trying to use offsetLeftandRight, by the offset I get in my
OnTouchListener, but it just crashes. code below:
// make a generic class to hold the click handler and touch
handler
public OnTouchListener imageTouchHandler = new OnTouchListener()
{
@Override
public boolean onTouch( View v, MotionEvent event )
{
float curX = event.getX();
float curY = event.getY();
float press = event.getPressure();
int offset = 0;
int histSize;
int histX;
double d;
// if this is an actual move, spring the offset to the
change in x
if( event.getAction() == MotionEvent.ACTION_MOVE )
{
histSize = event.getHistorySize();
histX = (int)event.getHistoricalX( histSize );
offset = (int)( histX - curX );
mainImage.offsetLeftAndRight( offset );
}
// also when the user is done moving, ACTION_UP, spring
to the left
or right side
if( event.getAction() == MotionEvent.ACTION_UP )
{
offset = mainImage.getLeft();
if( offset < -160 )
{
mainImage.offsetLeftAndRight( -320 );
}
else
{
mainImage.offsetLeftAndRight( 0 );
}
}
return true;
}
};
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---