Android: How to create a Facebook like images gallery grid?

前端 未结 2 1191
北恋
北恋 2020-12-29 17:09

I\'m trying to implement a facebook like, gallery grid, where items have different sizes:

I was trying to use different libraries/solutions but for now with

2条回答
  •  抹茶落季
    2020-12-29 17:43

    Finally, I have decided to use the TwoWayView library.

    That you can get from: https://github.com/lucasr/twoway-view

    In my code I did the following major changes:

    Added TwoWayView in the xml layout:

     
    

    In code I made the following changes:

    private TwoWayView mTwvGrid;
    .........
    
     mTwvGrid = (TwoWayView) findViewById(R.id.twvGrid);
        final Drawable divider = getResources().getDrawable(R.drawable.divider);
        mTwvGrid.addItemDecoration(new DividerItemDecoration(divider));
    
    
        mTwvGrid.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                RequestManager glideRequestManager = Glide.with(TimelineStoryActivity.this);
                if (newState == RecyclerView.SCROLL_STATE_IDLE || newState == RecyclerView.SCROLL_STATE_SETTLING) {
                    glideRequestManager.resumeRequests();
                } else {
                    glideRequestManager.pauseRequests();
                }
            }
    
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {}
        });
    .......
    
    if (mAdapter == null) {
                mAdapter = new TimelineStoryRecycleAdapter(this, mStory, mTwvGrid, this);
                mTwvGrid.setAdapter(mAdapter);
            } else {
                mAdapter.setStory(mStory);
            }
    

    Here is the end result:

提交回复
热议问题