Because to make a similar group of buy products. There is also an embedded ListView in the ScrollView, if the ListView is directly embedded into the ScrollView. The height of the listview is fixed and cannot be slid. By default, Android is forbidden to put additional scrollview in ScrollView, and its height cannot be calculated. This causes the listview height in the inside to be indeterminate, so only the code can be dynamically set up in the program such as the following:
public class Utility {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, listView); Listitem.measure (0, 0); Totalheight + = Listitem.getmeasuredheight (); } Viewgroup.layoutparams params = Listview.getlayoutparams (); Params.height = Totalheight + (listview.getdividerheight () * (Listadapter.getcount ()-1)); Listview.setlayoutparams (params); } }
Simply calling this static method after setting the adapter of the ListView allows the ListView to display correctly in the ListItem of its parent listview.
However, it is important to note that each item of the child ListView must be linearlayout, not other, because other layout (such as relativelayout) does not rewrite onmeasure (), so it will be in the Onmeasure () Throws an exception.
This enables the nested complex layout of the ScrollView plus ListView to be implemented.
Nested ListView in Android ScrollView