Question

I have a class that extends Gallery called MyGallery and I have a set of bitmaps to show in a MyGallery widget. In order to swipe only one item per gesture, I had to override the onFling() so it won't call the super.onFling(). The problem is that in order to change item, I have to swipe more than 50% of the screen size and it's bothering me. I did a search but I didn't find any ways to change this minimum limit. Is there any way to do this?

Was it helpful?

Solution

You can use the MotionEvent object to handle the minimum and maximum Swipe distances.
Calculate the swipe distance using the MotionEvent object i.e.., event.

@Override
public boolean onTouchEvent(MotionEvent event)
{
    // TODO Auto-generated method stub
    float rawX = 0.0f, dist;
    switch (event.getAction()) 
    {
    case MotionEvent.ACTION_DOWN:
        rawX = event.getX();
        break;
    case MotionEvent.ACTION_UP:
        dist = event.getX() - rawX;
        break;
    default:
        break;
    }
    return super.onTouchEvent(event);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top