Android GridView disables the swipe up and down and disables the display of the scroll bar.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.