The effect of merging two cells into one cell is shown in:
How to achieve the above results:
1. Get tablelayout.
2. Use tablelayout obtained in the first step to call the following method:
Private void appendtable (tablelayout ){
Int size = filelist. Size ();
Int columnnum = 4;
Boolean isspancell = false;
Boolean startnewrow = true;
Boolean endofonerow = false;
Table. setpadding (10, 0, 5, 0 );
// Obtain the fragment width of tablelayout,
Int width = fragment. getview (). getwidth ();
Tablerow ROW = NULL;
For (Int J = 0; j <size; j ++ ){
// The red code below todo is the rule for merging two adjacent cells I have defined. You can define your own merging rules.
If (J % columnnum = 0 ){
Startnewrow = true;
}
Else {
Startnewrow = false;
}
If (J % columnnum = 3 | j = size-1 ){
Endofonerow = true;
}
Else {
Endofonerow = false;
}
If (J % 5 = 0 | (J + 2) % 20 = 0 ){
Isspancell = true;
}
Else {
Isspancell = false;
}
If (startnewrow ){
Row = new tablerow (this. context );
}
View cell = generatecell (J, isspancell, width );
// Add new cells to the current row
Row. addview (cell );
// If a row ends, tablelayout adds the current row.
If (endofonerow ){
Row. setpadding (0, 0, 0, 10 );
Tablelayout. addview (ROW );
}
}
}
3. The method for green in step 2 is as follows:
Private view generatecell (INT index, Boolean isspanrow, int width ){
Viewholder holder = new viewholder ();
View view = NULL;
View = Inflater. Inflate (R. layout. file_item, null );
Tablerow. layoutparams TLP = new tablerow. layoutparams ();
TLP. span = 2; // tablerow. layoutparams, set cross-two columns
Linearlayout layout = new linearlayout (context );
Holder. filecreatoricon = (imageview) view
. Findviewbyid (R. Id. file_creator_icon );
Holder. filegridviewitemlayout = (relativelayout) view
. Findviewbyid (R. Id. file_gridview_item_relativelayout );
Holder. fileupdatedtime = (textview) view
. Findviewbyid (R. Id. file_upload_time );
Holder. fileownername = (textview) view. findviewbyid (R. Id. file_text_owner );
Holder. filename = (textview) view. findviewbyid (R. Id. file_name );
Layout. setpadding (0, 0, 10, 0 );
// Determine the width of the current cell based on whether it is cross-column, and dynamically calculate it based on the width of the current fragment.
If (isspanrow ){
Layout. addview (view, (width-40)/5*2 + 10,150 );
Layout. setlayoutparams (TLP );
}
Else {
Layout. addview (view, (width-40)/5,150 );
}
// Display the method of an item, which can be implemented according to your own situation
Showfileinfo (holder, index, view );
Return layout;
}