Android onFling not responding

后端 未结 5 1628
野的像风
野的像风 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: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);
            }
        };
    }
    

提交回复
热议问题