Android onFling not responding

后端 未结 5 1627
野的像风
野的像风 2020-12-30 13:28

I am new to android first of all so think of any newbie mistakes first

I am trying to add a fling function in my code.

public class MainGamePanel ext         


        
相关标签:
5条回答
  • 2020-12-30 13:48

    I tried the return value of onDown method to true, it didn't work. then i set ll_action_menu.setLongClickable(true);

    it worked

    0 讨论(0)
  • 2020-12-30 13:53

    For me I had to change the setLongClickable to true.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment, container, false);
        view.setLongClickable(true); // <---- here
        view.setOnTouchListener(getSwipeListener());
    
        return view;
    }
    
    public OnTouchListener getSwipeListener() {
        return new OnTouchListener() {
            private GestureDetector gesture = 
                    new GestureDetector(getActivity(),
                            new GestureDetector.SimpleOnGestureListener() {
                        @Override
                        public boolean onFling(MotionEvent e1, 
                                MotionEvent e2, 
                                float velocityX,
                                float velocityY) {
                            do some flinging here
                            return something
                        }
                    });         
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gesture.onTouchEvent(event);
            }
        };
    }
    
    0 讨论(0)
  • 2020-12-30 13:55

    onDown is called before the onFling event. If you return false in onDown method, the motion event propagation will stop.

    Try to change return false in return true at the end of onDown method.

    The return values are explained, somewhat obtusely, in the Input Events page of the Dev guide. (scroll down below the example code to see).

    0 讨论(0)
  • 2020-12-30 14:06

    You need to set your view longclickable, like this:

     yourView.setLongClickable(true);
    
    0 讨论(0)
  • 2020-12-30 14:07

    Ideally we should not be.. GestureDetector works differently when associated with Activity Vs when it is associated with View. There is already an issue reported.. click here for more details.

    0 讨论(0)
提交回复
热议问题