自定义的RecyclerView layout manager

一个自定义的RecyclerView layout manager ,可以将图片按照网格布局,并保持图片的长宽比。

效果

图片

使用说明

通过Gradle下载最新的版本:

repositories {

    maven { url 'https://github.com/500px/greedo-layout-for-android/raw/master/releases/' }

}



dependencies {

    compile 'com.fivehundredpx:greedo-layout:1.0.0'

}

 

要了解GreedoLayout完整的用法参见sample 项目。下面是几个特殊的步骤

// Create an instance of the GreedoLayoutManager and pass it to the RecyclerView

MyRecyclerAdapter recyclerAdapter = new MyRecyclerAdapter(this);

GreedoLayoutManager layoutManager = new GreedoLayoutManager(recyclerAdapter);

 

RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);

recyclerView.setLayoutManager(layoutManager);

recyclerView.setAdapter(recyclerAdapter);

 

// Set the max row height in pixels

layoutManager.setMaxRowHeight(300);

 

// If you would like to add spacing between items (Note, MeasUtils is in the sample project)

int spacing = MeasUtils.dpToPx(4, this);

recyclerView.addItemDecoration(new GreedoSpacingItemDecoration(spacing));

然后在你的RecyclerView adapter或者你选择的其它类中实现SizeCalculatorDelegate。这个实现将被传递到上面的 layout manager 。

public class MyRecyclerAdapter extends RecyclerView.Adapter<ViewHolder> implements SizeCalculatorDelegate {

    @Override

    public double aspectRatioForIndex(int index) {

        // Return the aspect ratio of your image at the given index

    }

}

源码请戳这里  http://pan.baidu.com/s/1slaklFR

来源  https://github.com/500px/greedo-layout-for-android

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值