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

时间:2019-02-11 16:46:32

标签: java android android-recyclerview

我正在尝试充实Get-AppPackage *YourTestAppNameHere* -AllUsers | Remove-AppPackage -AllUsers 中的所有项目,我的代码在RecyclerView以下的设备上不起作用,这是我的代码。

这是我的API 24类,它扩展了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;
        }
    }

1 个答案:

答案 0 :(得分:2)

创建RecycleView是为了优化负载,以免膨胀不必要的Itens。

如果您想对所有iten进行充气,也许您应该使用listview。