differentiating left and right scroll in gallery
Hie all , is there any method in android that can differentiate the left and the right scrolling actions in android.
it is actually a customized gallery view so what I am trying to do is that on scroll actions i want to differen开发者_StackOverflow社区t images. I mean on left scroll I've different images and on right scroll I've different images to show. so i need to differentiate the let and right scroll.Try this code:
new OnTouchListener() {
@Override
public boolean onTouch(View currentView, MotionEvent touchevent) {
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
if((oldTouchValue - currentX) < 50 && (oldTouchValue - currentX) > -50) {
return false;
}
if (oldTouchValue < currentX)
{
// Left swipe...
}
if (oldTouchValue > currentX)
{
// Right swipe
}
break;
}
}
return false;
}
}
精彩评论