Android:由于片段onClick,未调用活动onTouch

Android:由于片段onClick,未调用活动onTouch,android,android-fragments,Android,Android Fragments,我有一个片段,当你点击它时会显示一些文本,我希望我的活动能够拖动整个片段视图。我为包含片段的FrameLayout放置了一个onTouchListener,为片段放置了一个onClickListener。但我的听众永远不会被触发。如何从onClick传递onTouchEvent 下面是我代码的相关部分 活动\u question.xml <LinearLayout android:layout_width="match_parent" android:layout_heig

我有一个片段,当你点击它时会显示一些文本,我希望我的活动能够拖动整个片段视图。我为包含片段的FrameLayout放置了一个onTouchListener,为片段放置了一个onClickListener。但我的听众永远不会被触发。如何从onClick传递onTouchEvent

下面是我代码的相关部分

活动\u question.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/linearlayout_question">

    <include
        layout="@layout/toolbar_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@+id/framelayout_question_fragmentcontainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
问题片段

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_question, container, false);
    TextView textViewQuestion = (TextView) view.findViewById(R.id.textview_question_question);
    textViewQuestion.setText(mQuestion);

    final TextView textViewAnswer = (TextView) view.findViewById(R.id.textview_question_answer);
    textViewAnswer.setText(mAnswer);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            textViewAnswer.setVisibility(View.VISIBLE);
        }
    });
    return view;
}

您不需要onClick-您只能使用onTouch,它应该可以消除您的问题。在onTouch内部,您还可以使用
GestureDetector
或仅通过检测
MotionEvent.ACTION\u DOWN
MotionEvent.ACTION\u UP
来检测点击

如果要使用GestureDetector,请执行以下操作:

gestureDetector = new GestureDetector(this, new SingleTapConfirm());
在onTouch内部:

if (gestureDetector.onTouchEvent(arg1)) {
   // tap detected
   return true;
}

您不需要onClick-您只能使用onTouch,它应该可以消除您的问题。在onTouch内部,您还可以使用
GestureDetector
或仅通过检测
MotionEvent.ACTION\u DOWN
MotionEvent.ACTION\u UP
来检测点击

如果要使用GestureDetector,请执行以下操作:

gestureDetector = new GestureDetector(this, new SingleTapConfirm());
在onTouch内部:

if (gestureDetector.onTouchEvent(arg1)) {
   // tap detected
   return true;
}