One of the most popular ways to use it is
Public class utility {
Public static void setlistviewheightbasedonchildren (listview ){
Listadapter = listview. getadapter ();
If (listadapter = NULL ){
// Pre-condition
Return;
}
int totalheight = 0; arrears
for (INT I = 0; 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);
}< BR >} iphone5 news
This is too troublesome, and the effect is not very obvious.
A summary is as follows:
If you call this static method after setting the listview adapter, The listview can be correctly displayed in the listitem of its parent listview. However, it should be noted that each item in the sublistview must be linearlayout, but not others, because other layout (such as relativelayout) does not overwrite onmeasure (), so it will be in onmeasure () throw an exception.
another problem with nested listview (or scrollview) in scrollview is that the subscrollview cannot slide (if it is not completely displayed ), because the slide event will be eaten by the parent scrollview, if you want to let the child scrollview slide, you can only forcibly capture the slide event, some cool people posted Code in the Forum. Although I have not tried it myself, it is estimated that it is feasible.
although scrollview shows that the technical difficulties of scrollview can be broken, this design is very poor because it is difficult for users to see and operate on contents in the subscrollview. For example, a good design is that each item of the parent listview only displays a general description, and then click its item to go to another page to describe and display in detail and perform operations on this item.
find the other two simple methods without affecting them:
1. add an attribute Android: fillviewport = "true" to scrollview to display the listview in full screen.
2. specify the height of listview Android: layout_height = "420dp";