Android Only one item change per fling in gallery - android

I had implemented a custom Gallery with custom Adapter.
My Requirement is that however fast or slow does the user operates fling on the gallery only one item should change in the gallery.
I tried to override the Gallery's onFling method
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
//Log.e("VELOCITY ORIGINAL", ""+velocityX);
if (velocityX > 500) {//moving left
velocityX = 500.0f;
}else if(velocityX < -500){//moving right
velocityX = -500.0f;
}
//Log.e("VELOCITY MODIFIED", ""+velocityX);
return super.onFling(e1, e2, velocityX, velocityY);
}
But this did not produce desired results as sometimes it would flick one item and some times it won't.
Then I tried
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
But this completely disabled fling operation.
What could be the solution?

For that you have to override the onFling method in the Gallery class Try this and just Use ExtendedGallery instead of Gallery

Related

Cancel the effect of inertia in the movement of the maps in OSMDROID

I need to cancel the effect of inertia in the movement of the maps in OSMDROID. I tried to modify the code but I don't get anything. Any idea how?
Check onFling method in MapView.MapViewGestureDetectorListener class and change velocityX, velocityX to your implementation, something like:
#Override
public boolean onFling(final MotionEvent e1, final MotionEvent e2,
float velocityX,float velocityY) {
velocityX=(float) Math.sqrt(velocityX);
velocityY=(float) Math.sqrt(velocityY);
if (MapView.this.getOverlayManager()
.onFling(e1, e2, velocityX, velocityY, MapView.this)) {
return true;
}...

Gallery swipe adjustment

I need to lessen the amount of distance to be swiped in order to change my gallery's picture to the next. Right now this distance is at the standard rate and it's about half of the width of the gallery, but I need it to be about 1/3 or 1/4 of the total gallery width.
Thanks.
UPD: right now my custom gallery onFling returns false in order to list per page:
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}

How can I determine motion direction in an Android Gallery?

I have been creating a Gallery derivative that uses a limited number of Views and, as such, the Adapter needs to be able to populate these Views ahead of time during a scroll or a fling. To do this, I need to get the direction of motion from the onFling(...) and onScroll(...) events.
How can I use the distanceX parameter in onScroll(...) and the velocityX parameter in onFling(...) to determine which way the Gallery is travelling, and therefore which View to prepare next?
The signs of the velocity parameters in onFling(...) and the distance parameters on onScroll(...) are opposite. In order to correctly determine which direction a Gallery is moving, the code should be as follows:
#Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//if distanceX is POSITIVE, the Views are travelling left
//therefore the selection position is INCREASING
return super.onScroll(e1, e2, distanceX*mVelocityFactor, distanceY*mVelocityFactor);
}
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//if velocityX is NEGATIVE, the Views are travelling left
//therefore the selection position is DECREASING
return super.onFling(e1, e1, velocityX*mVelocityFactor, velocityY*mVelocityFactor);
}
By the way, mVelocityFactor is just a constant I introduced to make the scroll/fling a little less energetic. I found 0.6 to be quite a nice value—it still feels intuitive to scroll but the flings are less violent.

How to move popup window while user scroll window using gesture detector

I am placing a popup window while the user scrolls the window using gesture detector, but it's not updating to the correct position.
Can anybody tell me how to do this? Can anybody tell me how to update the position?
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
if(e1.getX() > e2.getX())
{
window.update((int)e1.getX(), (int)e1.getY(), -1, -1);
}
else
{
window.update((int)e2.getX(), (int)e2.getY(), -1, -1);
}
Simply you need the second MotionEvent Coordinates
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
window.update((int)e2.getX(), (int)e2.getY(), -1, -1);
}

How to detect scrolling action in Android?

I have a horizontal scroll view, and I want to detect a scrolling action ,
1) is there a listener to detect when the user make scrolling ?
2) and can I know whether the scroll is left to right or right to left ?
EDIT :what is the required listener in HorizontalScrollView ? I don't find OnScrollListener !
You need to go for Gestures. You will have callback methods like
onScroll(MotionEvent e1, MotionEvent
e2, float distanceX,float distanceY)
onFling(MotionEvent e1, MotionEvent
e2, float velocityX,float velocityY)

Categories

Resources