简体   繁体   English

如何一次在recyclerView中加载所有项目?

[英]How to load all items in recyclerView at once?

I'm trying to inflate all items in RecyclerView , My code is not working on devices below API 24 , here is my code. 我正在尝试在RecyclerViewRecyclerView所有项目,我的代码在API 24以下的设备上无法正常工作,这是我的代码。

This is my PreCachingLayoutManager class which extends LinearLayoutManager . 这是我的PreCachingLayoutManager类,它扩展了LinearLayoutManager

    public class PreCachingLayoutManager extends LinearLayoutManager {
        private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 800;
        private int extraLayoutSpace = -1;
        private Context context;

        public PreCachingLayoutManager(Context context) {
            super(context);
            this.context = context;
        }

        public PreCachingLayoutManager(Context context, int extraLayoutSpace) {
            super(context);
            this.context = context;
            this.extraLayoutSpace = extraLayoutSpace;
        }

        public PreCachingLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
            this.context = context;
        }

        public void setExtraLayoutSpace(int extraLayoutSpace) {
            this.extraLayoutSpace = extraLayoutSpace;
        }

        @Override
        protected int getExtraLayoutSpace(RecyclerView.State state) {
            if (extraLayoutSpace > 0) {
                return extraLayoutSpace;
            }
            return DEFAULT_EXTRA_LAYOUT_SPACE;
        }
    }

This is my activity code 这是我的活动代码

 dealsImagesRecyclerView = 
 findViewById(R.id.dealsImagesRecyclerView);
    layoutManager = new
            PreCachingLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    layoutManager.setExtraLayoutSpace(deviceHeight);
    layoutManager.setItemPrefetchEnabled(true);
    dealsImagesRecyclerView.setLayoutManager(layoutManager);

RecycleView is created to optimize the load, to not inflate unnecessary itens. 创建RecycleView是为了优化负载,而不是增加不必要的Iten。

If you wanna inflate all itens, maybe you should use listview. 如果您想对所有iten进行充气,也许您应该使用listview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM