Android:如何创建一个Facebook图像库网格? [英] Android: How to create a Facebook like images gallery grid?

查看:164
本文介绍了Android:如何创建一个Facebook图像库网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个类似facebook的网格,其中的项目具有不同的大小:



我试图使用不同的库/解决方案,但现在没有成功:


  1. 我尝试使用


    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 without success:

    1. I tried to use AsymemetricGridView. But the problem with this implementation is that there are empty dead spaces left in the grid after going throw the adapter.

    2. I also thought of using the StaggeredGridLayoutManager and a RecycleView, but items, in this case, don't have equal or half sizes to other items as it implemented in the Facebook gallery.

    Now I thinking of providing different view holders for different cases in the adapter, but I really don't like this idea. What is a better approach to this task?

    解决方案

    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:

     <org.lucasr.twowayview.widget.TwoWayView
                android:id="@+id/twvGrid"
                android:background="@android:color/white"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                style="@style/TwoWayView"
                app:twowayview_layoutManager="SpannableGridLayoutManager"
                app:twowayview_numColumns="3"
                app:twowayview_numRows="3" />
    

    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:

    这篇关于Android:如何创建一个Facebook图像库网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆