First, the Android processing mouse wheel event, is not the following function:
1) Public boolean onKeyDown (int keycode, keyevent event)
3) Public boolean ontouchevent (Motionevent event)
But the following function
Publicboolean ongenericmotionevent (Motionevent event);
All view and activity can override this function to handle wheel events on their own.
Many people on the web said that with the rewrite Dispatchtouchevent and ontouchevent method can be implemented to prohibit scrolling function, I tested the next, are not, only rewrite Ongenericmotionevent method can.
The specific code is as follows:
Import Android.annotation.suppresslint;import Android.content.context;import Android.util.log;import Android.view.motionevent;import Android.widget.gridview;public class MyGridView extends GridView {private static final String TAG = "freerdp.sessionactivity";p ublic MyGridView (context context) {super (context);//TODO auto-generated Constructor stub}//by re-dispatchtouchevent method to disable sliding @overridepublic boolean dispatchtouchevent (motionevent ev) {//TODO Auto-generated method STUBLOG.V (TAG, "dispatchtouchevent .... 4444444444 ... "+ ev.getaction ()); if (ev.getaction () = = Motionevent.action_move) {return true;//prohibit the GridView from sliding} return super.dispatchtouchevent (EV);} @Overridepublic boolean ontouchevent (Motionevent event) {//Override Ontouchevent callback method LOG.V (TAG, "dispatchtouchevent ... 5555 ... "+ event.getaction ()); switch (Event.getaction ()) {//press case MotionEvent.ACTION_DOWN:return Super.ontouchevent (event);//Slide case motionevent.action_move:break;//leave case MotionEvent.ACTION_UP:return Super.ontouchevENT (event);} Note: The return value is Falsereturn false;} @SuppressLint ({"Newapi", "Newapi"}) @Overridepublic Boolean ongenericmotionevent (Motionevent event) {// Override the Ontouchevent callback method switch (Event.getaction ()) {//Press case MotionEvent.ACTION_DOWN:return Super.ongenericmotionevent ( event),//sliding case motionevent.action_move:break;//leave case MotionEvent.ACTION_UP:return super.ongenericmotionevent ( event);} Note: The return value is Falsereturn false;}}
Second, prohibit scroll bar display
There are two ways to disable scroll bar display:
1. Add android:scrollbars= "None" attribute to XML.
2, Code implementation: Gridview.setverticalscrollbarenabled (FALSE);
Android GridView disables the swipe up and down and disables the display of the scroll bar.