Enables the GridView height of each item to stretch to reach the entire GridView just full screen effect.
Public Static voidsetgridviewmatchparent (GridView GridView) {//get the adapter of the GridViewListAdapter adapter =Gridview.getadapter (); if(Adapter = =NULL) { return; } //fixed column width, how many columns intCol =2;//Gridview.getnumcolumns (); intTotalheight =0; //I add 2 each time, the equivalent of Adapter.getcount () is less than or equal to 2 o'clock cycles once, calculates the height of the item once, Adapter.getcount () is less than or equal to 8 o'clock calculates two times the height is added for(inti =0; I < Adapter.getcount (); i + =Col) { //get each item in a ListViewView ListItem = Adapter.getview (i,NULL, GridView); Listitem.measure (0,0); //Gets the height of item andTotalheight + =listitem.getmeasuredheight (); } //Get layout parameters for GridViewViewgroup.layoutparamsparams=Gridview.getlayoutparams (); //Set Height params. Height =Totalheight; //Set Margin((Marginlayoutparams)params). SetMargins (Ten,Ten,Ten,Ten); //Setting ParametersGridview.setlayoutparams (params); }
Note To set the adapter before using this method:
Code taken from 45583029
Android settings GridView highly adaptive for full-screen full effect