Most of the time, the page where we use the ListView to load the data does not need a scollview on the outside of the ListView, because the ListView itself can scroll through the data. Sometimes we have to display other data in addition to the ListView to display the list data in the page, it is necessary to put a scollview on the entire page, otherwise the display may have problems (such as there are many other data on the ListView, Display on the phone directly led to the ListView is not visible, it will be in the entire screen layout plus Scollview implementation of sliding interface), with Scollview nested listview friends know, in the case of not doing task processing, The data of the ListView can only display a little more than one line, the others will not see, how to solve this problem? Usually we can have the following two ways:
1, calculate the height:
private int totalheight=0;
Public   static   void setlistviewheight (listview listview) {
/* Get Adapter */
Aadpter adapter = Listview.getadapter ();
/* Traverse control */
for ( int i = 0; i < ADAPTER&NBSP; . GetCount (); i++) {
View view = Adapter . GetView (i, null, listView);
/* Measure the height of the control suddenly */
view.measure ( View.measurespec. UNSPECIFIED , view.measurespec. UNSPECIFIED
Totalheight +=view.getmeasuredheight ();
}
/ * gap between controls * /
Totalheight +=listview.getdividerheight () * (Listview.getcount ()-1);
/*2, assigned to the Layoutparams object of the ListView */
Viewgroup.layoutparams params = Listview.getlayoutparams ();
params. Height = Totalheight ;
Listview.setlayoutparams (params);
}
2, rewrite the onmeasureof the ListView:
public class Wholelistview extends ListView {
PublicWholelistview(Context context) {
Super (context);
}
PublicWholelistview(context context, AttributeSet attrs) {
Super (context, attrs);
}
PublicWholelistview(context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
@Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
int expandspec = Measurespec.makemeasurespec (Integer.max_value >> 2,
Measurespec.at_most);
Super.onmeasure (Widthmeasurespec, Expandspec);
}
}
Of course, the above two methods are also effective for the GridView and Expandlistview.
Android Development in Scollview nested listview display Incomplete problem solving