Pinterest like custom GridView

后端 未结 4 1401
醉话见心
醉话见心 2021-02-07 16:31

I am new to android, and I am searching for a logic for grid view like pinterest(homescreen) app that has been build for i-phone. A large no. of images are coming from the serve

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 16:48

    This is old question, but for those that have similar problem:

    Easiest way to accomplish this layout style is to use RecyclerView with StaggeredGridLayoutManager, like this:

     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_activity);
    
        View recyclerView = findViewById(R.id.recycle_view);
        assert recyclerView != null;
        StaggeredGridLayoutManager gaggeredGridLayoutManager = new      
        StaggeredGridLayoutManager(2, 1);
            recyclerView.setLayoutManager(gaggeredGridLayoutManager);
    }
    

    For the other part of question (pagging) it's best to receive your images in chunks (for example 50 images per request) and when user scrolls down (comes to the end) load more.

提交回复
热议问题