A few days ago because of the needs of the project, to put another ListView in one ListView, you put another listview in each ListItem of a ListView. But in the beginning, you will find that the small ListView is not fully displayed, and its height is always problematic. Check the Internet, found that others have encountered such problems, and most people do not recommend such a design, because by default, Android is forbidden to put another scrollview in the ScrollView, its height is not calculated.
Search again, found that there are stackoverflow on the cow has solved the problem, after the experiment found that can solve the problem, its idea is to set up the ListView adapter, according to the ListView sub-project to recalculate the height of the ListView, Then set the height again as layoutparams to the ListView, so that its height is correct, the following is the source:
[HTML]View Plaincopyprint?
- 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);
- }
- }
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://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing
Android Combat tips: How to nest a ListView in ScrollView