Android implements a ListView non-scrolling effect

Source: Internet
Author: User
Tags gety

The desired effect is that the ListView cannot scroll, but the biggest problem with the ListView item is that there must be a click event. Assuming there is no need to click on the event that is simple, directly set listview.setenable (false);

Suppose you still need to click an event. 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 the distance between pressing and lifting the finger is very small, meeting the time limit of the Click event.

The ListView scrolling event is handled by itself. There are two inference conditions, which are determined as scrolling events when the user triggers a move event and the swipe exceeds the touch slop distance or the sliding speed exceeds the threshold.

Import Android.content.context;import Android.util.attributeset;import Android.view.motionevent;import     Android.widget.listview;public class Scrolldisabledlistview extends ListView {private int mposition;    Public Scrolldisabledlistview (Context context) {super (context);    } public Scrolldisabledlistview (context context, AttributeSet Attrs) {Super (context, attrs); } public Scrolldisabledlistview (context context, AttributeSet attrs, int defstyle) {Super (context, Attrs, DefS    Tyle); } @Override public boolean dispatchtouchevent (Motionevent ev) {final int actionmasked = ev.getactionmasked (         ) & Motionevent.action_mask; if (actionmasked = = Motionevent.action_down) {//record position when finger is pressed mposition = pointtoposition ((int)            TX (), (int) ev.gety ());        return super.dispatchtouchevent (EV); } if (actionmasked = = Motionevent.action_move) {//key place, ignore MOVE event//ListView ONtouch does not get the move event so scrolling will not occur return true;             }//If the finger is lifted (actionmasked = = Motionevent.action_up | | actionmasked = = motionevent.action_cancel) { The fingers are pressed and lifted in the same view. Given to the parent control, this is a click event if (pointtoposition (int) ev.getx (), (int) ev.gety ()) = = mposition) {Super.dis            Patchtouchevent (EV);                } else {//assuming that the finger has moved out of the pressed item, the description is scrolling, and the item pressed state setpressed (false) is cleared;                Invalidate ();            return true;    }} return super.dispatchtouchevent (EV); }}


Disable Scrolling in Android ListView

Disable Scrolling in ListView

Reprint please specify the source:

Android Settings ListView Non-scrollable

Android implements a ListView non-scrolling effect

Related Article

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: 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.