Android implements a ListView non-scrolling effect

Source: Internet
Author: User

The desired effect is that the ListView cannot scroll, but the biggest problem with the ListView item is also the Click event, if you do not need to click the event that is simple, directly set listview.setenable (false);

If you still need to click events, scrolling and clicking are all managed in the ListView Touch processing mechanism.

The ListView Click event is the processing logic of the multiplexed viewgroup, which triggers a click event when the user clicks on the view and moves a small distance between pressing and lifting the finger to meet the time limit of the Click event.

The ListView scrolling event is handled by itself, and there are two criteria for judging when the user triggers a move event and the swipe exceeds the touch slop distance or the sliding speed exceeds the threshold to be judged as a scrolling event.

1 ImportAndroid.content.Context;2 ImportAndroid.util.AttributeSet;3 Importandroid.view.MotionEvent;4 ImportAndroid.widget.ListView;5 6  Public classScrolldisabledlistviewextendsListView {7  8     Private intmposition;9  Ten      PublicScrolldisabledlistview (Context context) { One         Super(context); A     } -   -      PublicScrolldisabledlistview (Context context, AttributeSet attrs) { the         Super(context, attrs); -     } -   -      PublicScrolldisabledlistview (context context, AttributeSet attrs,intDefstyle) { +         Super(context, attrs, defstyle); -     } +   A @Override at      Public Booleandispatchtouchevent (motionevent ev) { -         Final intactionmasked = ev.getactionmasked () &Motionevent.action_mask; -   -         if(actionmasked = =Motionevent.action_down) { -             //record the position of the finger when it is pressed -Mposition = Pointtoposition ((int) Ev.getx (), (int) ev.gety ()); in             return Super. dispatchtouchevent (EV); -         } to   +         if(actionmasked = =motionevent.action_move) { -             //The most critical place to ignore the move event the             //ListView Ontouch does not get a move event so scrolling is not occurring *             return true; $         }Panax Notoginseng   -         //when your finger is lifted the         if(actionmasked = =motionevent.action_up +|| actionmasked = =motionevent.action_cancel) { A             //The finger is pressed and lifted in the same view, handed to the parent control to handle, which is a click event the             if(Pointtoposition (int) Ev.getx (), (int) ev.gety ()) = =mposition) { +                 Super. dispatchtouchevent (EV); -}Else { $                 //if the finger has moved out of the pressed item, the description is scrolling behavior, cleaning the item pressed state $Setpressed (false); - invalidate (); -                 return true; the             } -         }Wuyi   the         return Super. dispatchtouchevent (EV); -     } Wu}

(Transferred from: http://blog.csdn.net/androiddevelop/article/details/38815493)

Android implements a ListView non-scrolling effect

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.