http://m.blog.csdn.net/blog/yusewuhen/43706169
Reprint please specify the source:
http://blog.csdn.net/androiddevelop/article/details/38815493
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.
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 finger is pressed and lifted in the same view, handed to the parent control handle, which is a click event if (pointtoposition (int) ev.getx (), (int) ev.gety ()) = = Mposit ION) {super.dispatchtouchevent (EV); } else {//If the finger has moved out of the pressed item, the description is scrolling, the item pressed state setpressed (false) is cleared; Invalidate (); return true; }} return super.dispatchtouchevent (EV); }}
This method used with the ListView is not in ScrollView, when I put the ListView into the ScrollView to use this method, the discovery is not able to use normally, the solution of such problems please look down
Nested listview in ScrollView in Android resolves ListView scrolling issues
These days the project needs to be put into the ListView in ScrollView, and at first it was easy to think of an XML layout problem. But the actual operation to find the problem, you will find the ListView is not complete, its height is always a problem. There are also many people on the Internet that have this problem, most people do not recommend such a design, because by default, Android is forbidden to put another scrollview in the ScrollView, its height is not calculated.
But now that there is such a demand, it is going to happen. StackOverflow is really a good thing, found that already has the cow person solves this problem, after the experiment can solve this problem, its idea is after setting up the ListView adapter, calculates the listview height according to the ListView subproject, Then set the height again as layoutparams to the ListView, so that its height is correct, the following is the source:
public class Uihelper {public static void Setlistviewheightbasedonchildren (ListView listview) { ListAdapter ListAdapter = Listview.getadapter (); if (ListAdapter = = null) { //pre-condition return; } int totalheight = 0;for (int i = 0; i < Listadapter.getcount (); i++) {View ListItem = Listadapter.getview (i, NULL, list View); listitem.measure (0, 0); Totalheight + = Listitem.getmeasuredheight ();} Viewgroup.layoutparams params = Listview.getlayoutparams ();p arams.height = Totalheight + (Listview.getdividerheight () * (Listadapter.getcount ()-1)); Listview.setlayoutparams (params);} }
This static method is called after the adapter of the ListView is set so that the ListView is displayed correctly in the ListItem of its parent listview. Note, however, that each item of the child ListView must be linearlayout, not the other, because other layout (such as relativelayout) does not rewrite onmeasure (), so it will be in the Onmeasure () Throws an exception.
Another problem with nesting a ListView (or ScrollView) in ScrollView is that the child ScrollView cannot slide (if it is not shown), because the sliding event is eaten by the parent scrollview. If you want to let the sub-ScrollView can also slide, can only force interception of sliding events, there are cows in the forum sent code to say yes. Although I have not tried it myself, I think it is feasible.
While the technical challenges of ScrollView can be compromised in ScrollView, this design is a very poor user experience because it is not easy for users to see and manipulate the content in sub-scrollview. For example, a good design is that each item of the parent ListView only displays a general description, and then clicking on its item will go to another page to describe and display the item in detail.
Reference: Http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing
Android Settings ListView Non-scrollable and non-scrollable settings in ScrollView