Android settings GridView highly adaptive for full-screen full effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.