The use of scrollbars is a consequence of the uncontrolled height and width,
Before encountering a page that already has a scrollview need to add a list ListView, and then found that the ListView only see the first two rows of data, the following can not see, pull the scroll bar is just scrolling the entire page, not a ListView.
Method 1: Let the outside Scollview hand over the scrolling permission, because the listview itself has scroll bars.
Method 2: Calculate the list height after the content is loaded, and then set the height.
As long as you set the adapter to your ListView, and then reset the listview height, the idea is to figure out the height of each row, set the height of the listview to the height of each row * number of lines + the height of each line divider.
1 Public voidSetlistviewheightbasedonchildren (ListView listview) {2ListAdapter ListAdapter =Listview.getadapter (); 3 if(ListAdapter = =NULL) { 4 return; 5 } 6 intTotalheight = 0; 7 for(inti = 0; I < Listadapter.getcount (); i++) { 8View ListItem = Listadapter.getview (i,NULL, ListView); 9Listitem.measure (0, 0); TenTotalheight + =listitem.getmeasuredheight (); One } AViewgroup.layoutparams params =Listview.getlayoutparams (); -Params.height =Totalheight -+ (Listview.getdividerheight () * (Listadapter.getcount () + 1)); the listview.setlayoutparams (params); -}
When the ListView is passed in, the method changes its parameters and sets its height. 0.0
Resolves an issue where Android's ListView nesting cannot be scrolled in ScrollView