Android Gridlayoutmanager Certain item stand-alone line

Source: Internet
Author: User

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

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.