Why is my SimpleOnGestureListener not functioning?

后端 未结 2 773
[愿得一人]
[愿得一人] 2021-01-27 10:11

I\'m using my own GestureDetector class to detect a left|right onFling event. Everything I see looks good in my code but nothing happens...?

I need the added function

相关标签:
2条回答
  • 2021-01-27 10:18

    I think one reason is that Gesture work on onFling that condition not satisfied in u r code i have implemented one OntouchListener try this

    yourView.setOnTouchListner(onThumbTouch );
    
    
    
    
        OnTouchListener onThumbTouch = new OnTouchListener()
            {
                float previouspoint = 0 ;
                float startPoint=0;
                @Override
                public boolean onTouch(View v, MotionEvent event) 
                {   
                    switch(v.getId())
                    {
                    case R.id.tvDetailsalaujairiyat: // Give your R.id.sample ...
                    {
                        switch(event.getAction())
                        {
                        case MotionEvent.ACTION_DOWN:
                        {          
                            startPoint=event.getX();
                            System.out.println("Action down,..."+event.getX());
                        }
                        break;
                        case MotionEvent.ACTION_MOVE:
                        {       
    
                        }break;
                        case MotionEvent.ACTION_CANCEL:
                        {                           
    
                            previouspoint=event.getX();
                            if(previouspoint > startPoint){
                                //Right side swape
    
                            }else{
                            // Left side swape
                            }
    
                        }break;
    
                        }
                        break;
                    }
                    }
                    return true;
                }
            };
    
    0 讨论(0)
  • 2021-01-27 10:36

    I give credit to @Devunwired as he suggested above:

    If layout contains children that are also touchable, they may be stealing the events from their parent (your layout).

    So I added:

    View swipeView = (View) findViewById(R.id.animation_layout_content);
    swipeView .setOnTouchListener(new View.OnTouchListener() {...});
    

    Which works wonderfully now.

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