Listview is a common space in Android.
However, its height is sometimes difficult to control.
If the layout contains <scrollview/>, include the listview. The height of a unit is changed to the height of a unit.
Solution
/**
* Set the height of the list box to solve the scrolling problem.
*/
Private void initlistviewheight (listview list ){
Productlistadapter listadapter = (productlistadapter) List. getadapter ();
If (listadapter = NULL | listadapter. getcount () = 0 ){
Viewgroup. layoutparams Params = List. getlayoutparams ();
Params. Height = 0;
List. setlayoutparams (Params );
Return;
}
Int totalheight = 0;
For (INT I = 0; I <listadapter. getcount (); I ++ ){
View listitem = listadapter. getview (I, null, list );
Listitem. Measure (0, 0 );
Totalheight + = listitem. getmeasuredheight ();
}
Viewgroup. layoutparams Params = List. getlayoutparams ();
Params. Height = totalheight + (list. getdividerheight () * (listadapter. getcount ()-1 ));
Params. height + = 5;
List. setlayoutparams (Params );
}