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) ev.ge 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); }}
References:
Disable Scrolling in Android ListView
Disable Scrolling in ListView
Reprint please specify the source:
Android Settings ListView Non-scrollable
http://blog.csdn.net/androiddevelop/article/details/38815493
Android implements a ListView non-scrolling effect