I have a flipper:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/ParentLayout"
xmlns:android="http://schemas.android.com/apk/res/android" style="@style/MainLayout" >
<LinearLayout android:id="@+id/FlipperLayout" style="@style/FlipperLayout">
<ViewFlipper android:id="@+id/viewflipper" style="@style/ViewFlipper">
<!--adding views to ViewFlipper-->
<include layout="@layout/home1" android:layout_gravity="center_horizontal" />
<include layout="@layout/home2" android:layout_gravity="center_horizontal" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
The first layout,home1, consists of a scroll view. What should I do to distinguish between the flipping gesture and the scrolling? Presently:
- if I remove the scroll view, I can swipe across
- if I add the scroll view, I can only scroll.
I saw a suggestion that I should override onInterceptTouchEvent(MotionEvent), but I do not know how to do this. My code, at this moment, looks like this:
public class HomeActivity extends Activity {
-- declares
@Override
public void onCreate(Bundle savedInstanceState) {
-- declares & preliminary actions
LinearLayout layout = (LinearLayout) findViewById(R.id.ParentLayout);
layout.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}});
@Override
public boolean onTouchEvent(MotionEvent event) {
gestureDetector.onTouchEvent(event);
return true;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/
}
}
}
Can anybody please guide me in the right direction?
Thank you.