Encountered complex irregular columns (that is, some rows display more columns, some rows show fewer columns, and each column displays a different content page) for the solution before recyclerview out of this requirement, either the ListView nested Girdview, Either the direct use of the ScrollView, the effect is barely achievable, but both implementations have very large flaws-none of which can be reused for item.
With the Recyclerview, this kind of demand is solved, and the realization of this effect can better realize the idea of MVC, and can even change the display style of Recyclerview dynamically according to the data model. Really do the data control display style, and can be used to recycle the item.
You can use Gridlayoutmanager in conjunction with Gridlayoutmanager.spansizelookup's related features to create a new Gridlayoutmanager when the number of columns fills in the least common multiple of all possible columns. In combination with the adapter:
@Override Public int getitemviewtype (int position) { return00 : type; }
can be achieved. The key code to implement is as follows:
New 2 ); Layoutmanager.setspansizelookup (new gridlayoutmanager.spansizelookup () { @Override publicint getspansize (int position) { return0 21; } }); Ecyclerview.setlayoutmanager (LayoutManager);
The key code is on the top,
Layoutmanager.setspansizelookup
This code is a cross-column number that sets the item corresponding to the position location, such as the first row showing a column, and the other rows showing two columns of code implemented as follows:
Layoutmanager.setspansizelookup (new gridlayoutmanager.spansizelookup () { @Override Public int getspansize (int position) { return021 ; } });
Android Gridlayoutmanager Certain item stand-alone line