gridView with different cells sizes, pinterest style

后端 未结 3 1690
囚心锁ツ
囚心锁ツ 2020-11-28 06:25

Background

GridView is a class that extends AdapterView , which means it shows cells in a grid-style efficiently, recycling old views to be shown as new ones when

相关标签:
3条回答
  • 2020-11-28 06:39

    I think a RecyclerView with StaggeredGridLayoutManager can solve this issue, and that if you wish to also have a fast-scroller, you can try this library.

    So, no more trick are needed, as Google provided a solution...

    0 讨论(0)
  • 2020-11-28 06:49

    Is it a bit late to answer?

    check this library from etsy. it looks very promising.

    https://github.com/etsy/AndroidStaggeredGrid

    I think it is newer version of https://github.com/maurycyw/StaggeredGridView

    .

    Updated.

    Try using RecyclerView StaggeredGridLayoutManager from google instead

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(adapter);
    
    0 讨论(0)
  • 2020-11-28 06:54

    You may be able to accomplish this with a single ListView, where each cell contains a different grid template. I've done something similar to what you're describing, using this technique. If cell sizes need to be unique, this won't work, but it should be sufficient for the case you described:

    AABB
    AACC
    AADD
    AADD
    

    Creating a handful of templates like this, with various arrangements of A,B,C,D, you can then randomly use them as ListView cells and some simple offset math would allow your adapter to populate each subcell to accomplish something like the following:

    AABB
    AACC
    AADD
    AADD
    
    BBBB
    ACCC
    ADDD
    ADDD
    
    AAAA
    BBCC
    BBCC
    DDDD
    
    AABB
    AACC
    AADD
    AADD
    
    AABB
    AACC
    DDDD
    DDDD
    
    0 讨论(0)
提交回复
热议问题