Adding a ListView in ScrollView causes the ListView control to display incomplete because of a two-control scrolling event conflict. So it is necessary to calculate the display height of the ListView by the number of item in the ListView, so that it can be fully displayed, as follows to provide a method for everyone to refer to.
Example code:
Public voidSetlistviewheightbasedonchildren (ListView listview) {ListAdapter ListAdapter=Listview.getadapter ();if(ListAdapter = =NULL) { return; } intTotalheight = 0; for(inti = 0; I < Listadapter.getcount (); i++) {View ListItem= Listadapter.getview (I,NULL, ListView); Listitem.measure (0, 0); Totalheight+=listitem.getmeasuredheight ();} Viewgroup.layoutparams params=listview.getlayoutparams (); Params.height= Totalheight + (listview.getdividerheight () * (Listadapter.getcount ()-1)); Params.height+ = 5;//if without this statement,the listview would be a little shortlistview.setlayoutparams (params);}
Conflict issues with ScrollView and ListView