I have a ViewFlipper and in it, four scrollviews with layouts in those.
I use the following code (for each scrollview) to swipe:
ScrollView View1 = (ScrollView) findViewById(R.id.View1);
View1.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
FirstX = (int) event.getX();
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
int LastX = (int) event.getX();
if (FirstX - LastX > SWIPE_MIN_DISTANCE) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
} else if (LastX - FirstX > SWIPE_MIN_DISTANCE) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
}
}
return true;
}
});
It works, but it looks like if I swipe from View 1 to View 2, I see a views 2 and 3 mixed together and it finally shows view 4.
So it seems the OnTouchListeners for each view are called after eachother. How can I prevent this from happening?
A short and fast swipe does what it is supposed to do.
rg, Eric
You should move your code you have in MotionEvent.ACTION_MOVE
to MotionEvent.ACTION_UP
to get a swipe. Now, if you don't want swipe, and want to move the screen along with the finger, you should implement ViewPager
as JafarKhQ just mentioned.