In doing a project, the layout of this project can be quite complex, the outermost is the ScrollView, in the scrollview inside there are two ListView, this good, layout out, put on the machine run, card to want to die have wood, information disorderly appearance, said very headache.
Baidu after the internet, found that someone solved the problem, then the solution reprinted to share.
The idea is that after setting the adapter of the ListView, the ListView's height is recalculated according to the child items of the ListView, and then the height is then set to the ListView as Layoutparams so that it is the correct height.
Public classUtility { Public Static voidSetlistviewheightbasedonchildren (ListView listview) {ListAdapter ListAdapter=Listview.getadapter (); if(ListAdapter = =NULL) { //pre-condition 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)); 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://blog.csdn.net/hitlion2008/article/details/6737459
Reprint Please specify source: http://www.cnblogs.com/yydcdut/p/3766414.html