A method of merging grids in Setspansizelookup-recyclerview

Source: Internet
Author: User

Recyclerview from out to now basically widely used, but for me such a lot of things will not be used. Basic use includes ListView mode and GridView mode, recently using the GridView pattern, which is using Gridlayoutmanager to discover a useful method that can be used as a table merge cell in Word, merging some cells.

Using the method, call a method after getting Gridlayoutmanager:

Specific use
Gridlayoutmanager. (New Gridlayoutmanager.spansizelookup () {
            @Override public
            int getspansize (int position) {
                int type = Indexrecyclerview.getadapter (). Getitemviewtype (position);//Get return value
                //logutils.e ("TAG", "type:" +type);
                if (type = = 1 | | type = = 2 | | type = = 3) {
                    return 2;//two
                } else {
                    return 1;}}
        );
Gets the type by combining the Getitemviewtype (position) method of the Recyclerview adapter.
@Override public
int getitemviewtype (int position) {
//LOGUTILS.E ("TAG", "Position-type:" +position); 
   if (position = = 0) {
return type_viewpager;
} else if (position = = 1) {
return type_operation;
} else if (position = = 2) {
return type_guider;
} else {
return type_gridview;
}
}

With this approach, we can easily merge a few grids in Gridvewi mode. Record here for easy follow-up search

The previous writing has been changed, no effect diagram, on the Internet to find an effect chart as follows: (the image below is the effect of merging the first second cell)


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.