Android Fragment onCreateView with Gestures

前端 未结 2 1016
轮回少年
轮回少年 2020-12-02 20:57

I\'m attempting to utilize Gestures within a fragment; I have the following inside of a FragmentActivity which handles my details fragment. What I am attempting to have hap

2条回答
  •  遥遥无期
    2020-12-02 21:11

    a couple comments

    1. I had to tweak my code as follows:

      v.setOnTouchListener(new View.OnTouchListener() {
          @Override        
          public boolean onTouch(View v, MotionEvent event) {
      
              // return gesture.onTouchEvent(event);
      
              gesture.onTouchEvent(event);
              return true; // <-- this line made the difference
          }
      });
      
    2. Also, if you are using an xml file to create your view

      View v = inflater.inflate(R.layout.my_view, null, false);
      

    make sure you are actually pressing the intended view. A nice way to exaggerate the test is to make both the width and the height to "match_parent" instead of "wrap_content" in your layout xml file.

提交回复
热议问题