I'm implementing a fragment with a scrollview and I want to detect left to right swipe in this fragment. I've used the following code to detect the swipe event:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final GestureDetector gesture = new GestureDetector(getActivity(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                                       float velocityY) {
                    Log.i("SWIPE", "onFling has been called!");
                    final int SWIPE_MIN_DISTANCE = 120;
                    final int SWIPE_MAX_OFF_PATH = 250;
                    final int SWIPE_THRESHOLD_VELOCITY = 200;
                    try {
                        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
                            return false;
                        }
                        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                            Log.i("SWIPE", "Right to Left");
                        }
                        else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                            Log.i("SWIPE", "Left to Right");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return super.onFling(e1, e2, velocityX, velocityY);
                }
            });
    container.setOnTouchListener(new View.OnTouchListener()
                {
                    @Override
                    public boolean onTouch (View v, MotionEvent event){
                    return gesture.onTouchEvent(event);
                }
                });
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_blank, container, false);
}
I've tested this code without the scrollview in the layout and it worked fine. Bus as soon as I insert the scrollview in the layout the swipe event stop being detected.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.doutvisions.teste.BlankFragment"
android:id="@+id/scrollView1">
<TextView
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/hello_blank_fragment" />
</ScrollView>
Anyone can please help? I would appreciate.
