Home > Mobile >  How to monitor a particular view sliding event?
How to monitor a particular view sliding event?

Time:01-26

I look at the official documentation is written, so if I want to monitor a particular view, how should change?

 
Public class MainActivity extends the Activity {

Private GestureDetectorCompat mDetector;

@ Override
Public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
MDetector=new GestureDetectorCompat (this, new MyGestureListener ());
}

@ Override
Public Boolean onTouchEvent (MotionEvent event) {
//here, for example, I want to listen textView1, should how to write
This. MDetector. OnTouchEvent (event);
Return super. OnTouchEvent (event);
}

The class MyGestureListener extends GestureDetector. SimpleOnGestureListener {
Private static final String DEBUG_TAG="Gestures";

@ Override
Public Boolean onDown (MotionEvent event) {
The d (DEBUG_TAG, "onDown:" + event. The toString ());
return true;
}

@ Override
Public Boolean onFling (MotionEvent event1, MotionEvent event2,
{float velocityX, float velocityY)
The d (DEBUG_TAG, "onFling:" + event1. ToString () + event2. ToString ());
return true;
}
}
}


CodePudding user response:

To want to listen to the view to register this onTouchEvent event, tend to have similar setOnTouch... The Listener, code written to rewrite the anonymous interface implementation in the interface.

CodePudding user response:

GestureDetectorCompat is to monitor your finger in the current screen click or sliding, so why do you want to monitor textView1?

CodePudding user response:

refer to the second floor hasn't bald hair a reply:
GestureDetectorCompat is to monitor your fingers click slide or event in the current screen, so why do you want to monitor textView1?


Because I want these gesture only function in a View, if beyond this textView1, don't trigger,,

CodePudding user response:

reference coolestingx reply: 3/f
Quote: refer to the second floor hasn't bald hair a reply:
GestureDetectorCompat is to monitor your fingers click slide or event in the current screen, so why do you want to monitor textView1?


Because I want these gesture only function in a View, if beyond this textView1, not triggered,,


Then you have to get first textView1 area, such as textView1 the upper-left corner at (0, 0), in the top right corner (100, 0), the lower right corner in (100, 100), in the lower left (0, 100), and then in MyGestureListener judgment fingers now contact the coordinates of the screen is in this area

CodePudding user response:

refer to 4th floor hasn't bald hair a reply:
Quote: refer to the third floor coolestingx response:
Quote: refer to the second floor hasn't bald hair a reply:
GestureDetectorCompat is to monitor your finger in the current screen click or sliding in the event, so why do you want to monitor textView1?


Because I want these gesture only function in a View, if beyond this textView1, not triggered,,


Then you have to get first textView1 area, such as textView1 the upper-left corner at (0, 0), in the top right corner (100, 0), the lower right corner in (100, 100), in the lower left (0, 100), and then in MyGestureListener judgment fingers now contact the coordinates of the screen is in this area


Wow, this trouble ah, then, that it is better to use setOnTouchListener...
  • Related