In ScrollView, add the adapter after the ListView GridView adds
Set the height of the GridView overall
public void Setlistviewheightbasedonchildren (GridView GridView) {
Get the adapter for the ListView
if (adapter== null) {
Return
}
int totalheight = 0;
for (int i = 0, Len = adapter.getcount (); i < Len; i++) {//
Listadapter.getcount () returns the number of data items
View ListItem = Adapter.getview (i, NULL, GridView);
Listitem.measure (0, 0); Calculate the width height of a child view
Totalheight + = Listitem.getmeasuredheight (); Count All children
The total height
}
Viewgroup.layoutparams params = Gridview.getlayoutparams ();
Params.height = Totalheight
+ (Gridview.getheight () * (Adapter.getcount ()-1));
Listview.getdividerheight () Gets the height of the delimiter between children
Params.height finally get the entire ListView full display required height
Gridview.setlayoutparams (params);
}
The equivalent of putting them up with scrollview scrolling view
Add Android:focusableintouchmode= "true" to the parent element of the ListView GridView
Android:focusable= "true" to prevent them from getting focus when they unfold let the parent element get focus
Prevent the parent control from intercepting touch events in ScrollView
Gridview.setontouchlistener (New Ontouchlistener () {
@Override
public boolean OnTouch (View V, motionevent event) {
Gridview.getparent (). Requestdisallowintercepttouchevent (True);
Return false;//not consuming current events
}
});
ScrollView ListView The conflict between the GridView