RecycledViewPool的使用和堆内存分析

本文探讨了RecycledViewPool在ViewPager配合RecyclerView场景中的应用,通过实例展示了如何利用RecycledViewPool减少ViewHolder实例,节省内存并提高滑动流畅性。通过对比分析,证明了RecycledViewPool在减少CreateViewHolder资源开销和优化性能方面的作用。提供了相关代码仓库链接,邀请读者进一步研究。
摘要由CSDN通过智能技术生成

RecycledViewPool在
ViewPager+RecyclerView的场景下可以大放光彩。
下面就来验证一下它的优点:

首先我们自定定义一个View放在ViewHolder中:


public class FloorView extends ImageView {
//这里如果数组大于0可以放大FloorView的内存占用。
    private Bitmap[] bitmaps=new Bitmap[0];
    public FloorView(Context context) {
        super(context);
        init();
    }

    public FloorView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FloorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        for (int i = 0; i < bitmaps.length; i++) {
            bitmaps[i]= BitmapFactory.decodeResource(getResources(),R.drawable.pic1);
        }
        Log.e("lmtlmt","init");

    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
       
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值