如何使用网格布局管理器来recyclerview设置不同大小的图像?

时间:2019-06-26 12:31:33

标签: android android-recyclerview android-gridview android-gridlayout

我想使类别ui像下面的android中一样。我正在将recyclerview与网格布局管理器一起使用。但是我无法在android中像这样设计来管理它。

enter image description here

3 个答案:

答案 0 :(得分:0)

您可以如下使用StaggeredGridLayout。

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
CustomAdapter customAdapter = new CustomAdapter(MainActivity.this,images);
recyclerView.setAdapter(customAdapter);

答案 1 :(得分:0)

I have managed span of images in adapter class like below.
 private static final int TYPE_SMALL_SQUARE = 0;
 private static final int TYPE_LARGE_SQUARE = 1;
 private static final int TYPE_LREACT = 2;
 private static final int TYPE_HREACT = 3;
  @Override
    public int getItemViewType(int position) {
        switch (position) {
            case 0:
                return TYPE_LARGE_SQUARE;
            case 1:
                return TYPE_HREACT;
            case 2:
                return TYPE_LREACT;
            case 3:
                return TYPE_LREACT;
            case 4:
                return TYPE_SMALL_SQUARE;
        }
        return super.getItemViewType(position);
    }

答案 2 :(得分:0)

 import os, shutil, time

 if not os.path.exists(dirName):
    os.mkdir(dirName)
    print("Directory " , dirName ,  " Created ")
 else:    
    print("Directory " , dirName ,  " already exists")

def copyFile(src, dest):
    try:
        shutil.copy(src, dest)
    # eg. src and dest are the same file
    except shutil.Error as e:
        print('Error: %s' % e)
    # eg. source or destination doesn't exist
    except IOError as e:
        print('Error: %s' % e.strerror)

os.rename("path/to/current/age.csv", "path/to/new/destination/for/age.csv")
shutil.move("path/to/current/age.csv", "path/to/new/destination/for/age.csv")