Android 在子片段中未检测到触摸

Android 在子片段中未检测到触摸,android,android-fragments,gesture,ontouchlistener,gesturedetector,Android,Android Fragments,Gesture,Ontouchlistener,Gesturedetector,当我将侦听器附加到片段的子片段时,onTouchListener出现问题。我尝试了许多其他的解决方案,但听众似乎不起作用。GestureDetector代码取自此处: main_activity.xml <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/home_drawer_layout"

当我将侦听器附加到片段的子片段时,onTouchListener出现问题。我尝试了许多其他的解决方案,但听众似乎不起作用。GestureDetector代码取自此处:

main_activity.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/home_content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView android:id="@+id/home_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/functionPad"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:background="@drawable/gradient_home_background"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/row1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/bgPanelResult">

        <TextView
            android:id="@+id/panelResult"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end|center_vertical"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="60sp" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/keypadFrame"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/row1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</RelativeLayout>

为父级相对布局而不是根视图调用touch事件。我尝试了
getActivity().findViewById(R.id.functionPad)
,但它仍然不起作用。我正在使用ChildFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.child_fragment, container, false);

        // Gesture detection
        gestureDetector = new GestureDetector(getActivity(), new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        };


        rootView.findViewById(R.id.keypadSimple).setOnTouchListener(gestureListener);

        return rootView;
    }


    class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Toast.makeText(getActivity(), "Left Swipe", Toast.LENGTH_SHORT).show();
                }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Toast.makeText(getActivity(), "Right Swipe", Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    }